Support » Themes and Templates » The_Content() and recent post in category

  • Resolved jfburroway

    (@jfburroway)


    I’m trying to create a single “sticky” for a weekly podcast (postcasts are category 39) at the top of my blog. I want to display the title and the text. I can get the title to show up, but the text (the_content()) is blank.

    The same post shows up in the more conventional loop in the main part of the blog. What’s wrong?

    <?php
     $myposts = get_posts('numberposts=1&category=39');
     foreach($myposts as $post) :
     ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <?php the_content(); ?>
     <?php endforeach; ?>

    the_permalink() and the_title() work fine, but the_content() returns nothing.

    test.boxturtlebulletin.com

Viewing 3 replies - 1 through 3 (of 3 total)
  • Not resolved yet. … raising above another accidental duplicate post… Yes, it’s one of those days.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    When you use get_posts(), you don’t automatically fill up the internal variables to make the template tags like the_content work properly. You have to call setup_postdata with the post to force that to occur.

    So, change it to this:

    <?php
     $myposts = get_posts('numberposts=1&category=39');
     foreach($myposts as $post) : setup_postdata($post);
     ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <?php the_content(); ?>
     <?php endforeach; ?>

    You’re a genius! And fast too!

    A billion thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘The_Content() and recent post in category’ is closed to new replies.