0

In my single.php I have this

<?php
while ( have_posts() ) : the_post();

    get_template_part( 'template-parts/content-single', get_post_type() );

endwhile;

And my content-single.php

<div class="blog-post">
    <h2 class="blog-post-title"><?php the_title(); ?></h2>
    <p class="blog-post-meta"><?php the_date(); ?> by <a href="#"><?php the_author(); ?></a></p>
<?php the_content(); ?>
</div>

But when I view a post it only displays title, date and author but not the content of the post

If I put <?php the_content(); ?> in content.php and change template-parts/content-single to template-parts/content then it displays but mess up my Homepage (my homepage must not display the_content() )

Do I miss something or do something wrong?

  • 1
    Use an HTML validator to find unclosed tags. Also, may be the content is downloaded but is not shown. Check the page source and use Developer Tools to check content CSS. – Max Yudin Sep 3 '17 at 10:00
0

I figured it out, it's actually the naming problem
For anyone or newbies have the same problem:

You cannot get content like this: get_template_part( 'template-parts/content-single')

You should fix it like this: get_template_part( 'template-parts/content', 'single' )

  • 'template-parts/content-single' and 'template-parts/content', 'single' will do exactly the same thing. In your code you had 'template-parts/content-single', get_post_type() though, which would find content-single-post.php/content-single-page.php. If that file exists then that's what it would have been using, and why changes to content-single.php wouldn't have been reflected where you expected. – Jacob Peattie Sep 3 '17 at 8:30
  • If I remove the get_post_type() I get a blank page – superquanganh Sep 3 '17 at 8:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.