Wordpress Single post content not showing up

2019-04-14 10:28发布

问题:

I've got a wordpress blog theme which shows the content of all posts on the index fine but when I click into one of the posts the content of the post is blank and I can't seem to figure out why. If I'm correct the single.php controls that page.

http://pastebin.com/afLVxMPb = My single.php

an example of what I mean would be http://www.ndesign-studio.com/demo/wordpress/blog/how-about-a-blog-post-with-longer-title but on this site the content of the blog post does show up but on mine it doesn't.

I think the problem is somewhere here...

<div class="entry-content">
      <?php the_content(); ?>
     <?php wp_link_pages('before=<div class="page-link">' . __( 'Pages:', 'your-theme' ) . '&after=</div>') ?>
</div><!-- .entry-content -->

回答1:

You should add "the loop" somewhere in your single.php file and call setup_postdata($post) or the_post() so you can access the post data inside that loop.

Read more about the loop here: http://codex.wordpress.org/The_Loop

For example, your single.php file will look something like this (simplified):

........
<div id="content">
    <?php if(have_posts()) : the_post(); ?>
        <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
            <h1 class="entry-title"><?php the_title(); ?></h1>
            // etc.. all post info

............

<?php endforeach; ?>

Hope that helps! Good luck.