I have a single post template created for a custom post type called Places. The template file is named single-places.php and is behaving as expected for single Places post entries.
I have several custom fields that were created using the MoreFields plugin, and they all are showing as expected, as are post thumbnails and titles.
The problem I am encountering is that the_content()
is not returning the content from the post. I am using what you might call the "typical" loop:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
I came across some mentions of having to use setup_postdata($post)
with custom post types for the_content()
to work properly, but I haven't been able to find an example of how to use it in the context of my template.
Any help/insight would be appreciated. Cheers!
Maor Barazany answers:
What do you have instead of the content displayed?
Try for testing to replace
<?php the_content(__('Read more...', 'framework')); ?>
with -
<?php echo get_the_content;?>
or -
<?php echo $post->post_content;?>
Also, check in your database that the content is being saved there at first place. If it is not saved, it won't be retrieved..
John Lopez comments:
Nothing was being displayed with
<?php the_content(__('Read more...', 'framework')); ?>
aside from the custom fields.
Using your "echo" works! Would it be considered "bad form" to keep those in place? Let me know if you think it's OK to use the echo solution, or if we should be looking at something else.
Maor Barazany comments:
You can use the echo get_the_content() function, but it won't apply any of content filters if in case you use such of them.
It might be that one of your plugins or theme functions makes the_content() not to be shown for some reason.
If you want to test this issue you should try disable all plugins and see if regular the_content() gets back to work, or switch to default 2010 theme and do the check.
If not, you can keep using the cho get_the_content() .
The 2nd echo is less recommended as it can be less secured to spit out data from db.
Maor Barazany comments:
Also, do you use the "read more" functionality at all?
If not, try using only -
<?php the_content(); ?>
instead of -
<?php the_content(__('Read more...', 'framework')); ?>
Liesl Fawcett answers:
Hi. Could you provide the entire single-places.php file?
John Lopez comments:
<?php get_header(); ?>
<?php /* include theme options */ include( TEMPLATEPATH . '/functions/get-options.php' ); ?>
<!--BEGIN #primary .hfeed-->
<div id="primary" class="hfeed">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<!--BEGIN .hentry -->
<div <?php post_class('rounded') ?> id="post-<?php the_ID(); ?>">
<?php if ( function_exists('yoast_breadcrumb') ) : ?> <p class="breadcrumb"><?php yoast_breadcrumb(); ?></p><?php endif; ?>
<!-- BEGIN #gallery-single-columns -->
<div id="gallery-single-columns" class="clearfix">
<!-- BEGIN #gallery-single-column-left-->
<div id="gallery-single-column-left" class="post-featured-content rounded">
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { /* if post has post thumbnail */ ?>
<div class="gallery-post-thumb">
<?php the_post_thumbnail('gallery-image'); /* post thumbnail settings configured in functions.php */ ?>
</div>
<?php } ?>
<!--BEGIN .entry-meta .entry-header-->
<div class="entry-meta entry-header gallery-info">
<h1 class="entry-title single-entry-title gallery-title"><?php the_title(); ?></h1>
<a href="<?php more_fields('gallery_url'); ?>" title="<?php the_title(); ?>: <?php more_fields('gallery_url'); ?>"><?php more_fields('gallery_url','<p>','</p>'); ?></a>
<?php more_fields('gallery_address','<p>','</p>'); ?>
<?php more_fields('gallery_hours','<p>','</p>'); ?>
<?php more_fields('gallery_admission','<p>','</p>'); ?>
<?php more_fields('gallery_phone','<p><strong>TEL: </strong>'); ?><br />
<?php more_fields('gallery_fax','<strong>FAX: </strong>'); ?><br />
<?php more_fields('gallery_email',' ','</p>'); ?>
<p><a href="<?php more_fields('gallery_facebook'); ?>" title="<?php the_title(); ?>: <?php more_fields('gallery_facebook'); ?>"><?php more_fields('gallery_facebook','<strong>FB: </strong>'); ?></a><br />
<a href="<?php more_fields('gallery_twitter'); ?>" title="<?php the_title(); ?>: <?php more_fields('gallery_twitter'); ?>"><?php more_fields('gallery_twitter','<strong>TWITTER: </strong>'); ?></a><br />
<a href="<?php more_fields('gallery_blog'); ?>" title="<?php the_title(); ?>: <?php more_fields('gallery_blog'); ?>"><?php more_fields('gallery_blog','<strong>BLOG: </strong>'); ?></a></p>
<!--END .entry-meta entry-header -->
</div>
<!--BEGIN .entry-content -->
<div class="entry-content">
<?php the_content(__('Read more...', 'framework')); ?>
<?php wp_link_pages(array('before' => '<p><strong>'.__('Pages:', 'framework').'</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
<!--END .entry-content -->
</div>
</div>
<!-- BEGIN #gallery-single-column-right-->
<div id="gallery-single-column-right">
<?php if ($tz_sharing_enable == "true") { /* Display 468x60 banner if checked in theme options */ ?>
<ul class="share">
<?php if ($tz_enable_twitter == "true") { /* Display Twitter link if checked in theme options */ ?>
<li class="tweet"><a href="http://twitter.com/home/?status=<?php the_title(); ?> - <?php the_permalink(); ?>">Tweet this post</a></li>
<?php } ?>
<?php if ($tz_enable_fb == "true") { /* Display Facebook link if checked in theme options */ ?>
<li class="fb"><a href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>?t=<?php the_title(); ?>" title="Post to Facebook">Post to Facebook</a></li>
<?php } ?>
<?php if ($tz_enable_digg == "true") { /* Display Digg link if checked in theme options */ ?>
<li class="digg"><a href="http://digg.com/submit?url=<?php the_permalink();?>&title=<?php the_title(); ?>&thumbnails=1" title="Digg this!">Digg this!</a></li>
<?php } ?>
<?php if ($tz_enable_reddit == "true") { /* Display Reddit link if checked in theme options */ ?>
<li class="reddit"><a href="http://www.reddit.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Share on Reddit">Share on Reddit</a></li>
<?php } ?>
<?php if ($tz_enable_del == "true") { /* Display Deliciouos link if checked in theme options */ ?>
<li class="del"><a href="http://del.icio.us/post?url=<?php the_permalink();?>&title=<?php the_title(); ?>" title="Add To Delicious">Add to Delicious</a></li>
<?php } ?>
<?php if ($tz_enable_stumble == "true") { /* Display Stumble link if checked in theme options */ ?>
<li class="stumble"><a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>" title="Stumble this">Stumble this</a></li>
<?php } ?>
<?php if ($tz_enable_gbuzz == "true") { /* Display Google Buzz link if checked in theme options */ ?>
<li class="gbuzz"><a href="http://www.google.com/reader/link?title=<?php the_title();?>&url=<?php the_permalink();?>" title="Google Buzz">Google Buzz</a></li>
<?php } ?>
<?php if ($tz_enable_ybuzz == "true") { /* Display Yahoo Buzz link if checked in theme options */ ?>
<li class="ybuzz"><a href="http://buzz.yahoo.com/submit/?submitUrl=<?php the_permalink(); ?>&submitHeadline=<?php the_title(); ?>" title="Yahoo Buzz">Yahoo Buzz</a></li>
<?php } ?>
<?php if ($tz_enable_techno == "true") { /* Display Technorati link if checked in theme options */ ?>
<li class="techno"><a href="http://technorati.com/signup/?f=favorites&Url=<?php the_permalink(); ?>" title="Post to Technorati">Post to Technorati</a></li>
<?php } ?>
<?php if ($tz_enable_linkedin == "true") { /* Display Linkedin link if checked in theme options */ ?>
<li class="linkedin"><a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php the_permalink(); ?>&title=<?php the_title(); ?>&source=" title="Share on Linkedin">Share on Linkedin</a></li>
<?php } ?>
<?php if ($tz_enable_email == "true") { /* Display email link if checked in theme options */ ?>
<li class="email"><a href="mailto:?subject=<?php the_title(); ?>&body=<?php the_permalink(); ?>">Email a friend</a></li>
<?php } ?>
</ul>
<?php } ?>
<ul class="rss">
<?php
foreach((get_the_category()) as $category) { // Get all categories of that post
$tz_slug = $category->category_nicename;
$tz_url = get_bloginfo('url');
$tz_catname = $category->cat_name;
// Display feed links for each category
echo '<li><a href="'.$tz_url.'/category/'.$tz_slug.'/feed">'.$tz_catname.'</a></li>';
}
?>
</ul>
<!-- END #single-column-right-->
</div>
<!-- END #single-columns -->
</div>
<!--END .hentry-->
</div>
<?php comments_template('', true); ?>
<!--BEGIN .navigation .single-page-navigation -->
<div class="navigation single-page-navigation">
<div class="nav-previous"><?php previous_post_link('← %link') ?></div>
<div class="nav-next"><?php next_post_link('%link →') ?></div>
<!--END .navigation .single-page-navigation -->
</div>
<?php endwhile; else: ?>
<!--BEGIN #post-0-->
<div id="post-0" <?php post_class() ?>>
<h1 class="entry-title"><?php _e('Error 404 - Not Found', 'framework') ?></h1>
<!--BEGIN .entry-content-->
<div class="entry-content">
<p><?php _e("Sorry, but you are looking for something that isn't here.", "framework") ?></p>
<?php get_search_form(); ?>
<!--END .entry-content-->
</div>
<!--END #post-0-->
</div>
<?php endif; ?>
<!--END #primary .hfeed-->
</div>
<?php get_footer(); ?>