Posts on home page displaying excerpts from other posts

I’m having a strange problem. I created a custom home page template to pull the latest 5 posts from two different categories into the layout (see “Learn and “Play” columns).

http://sensoryrevolution.com.s177767.gridserver.com/

Read More

I’m pulling in 4 fields through a custom query I copied+pasted from this very site:

  • Post thumbnail
  • Permalink
  • Post title
  • Excerpt

Only the excerpt is wrong. It’s displaying the excerpt from the blog post above it.

Here’s the code I’m using to pull this in. The weird thing is that it was working, and now it’s broken. I’ve backed out some other custom code I had that was limiting the number of characters in the excerpt, so this is purely the_excerpt() working its magic.

<?php $posts = get_posts('category=213&orderby=desc&numberposts=5'); foreach($posts as $post) { ?>
    <h4><a href="<?php the_permalink() ?>" target="_parent"><?php the_title(); ?></a></h4>
    <a href="<?php the_permalink() ?>" target="_parent"><?php the_post_thumbnail('blog-large'); ?></a>
    <p><?php the_excerpt() ?><?php // echo excerpt(22) ?></p>
<?php } ?>

This is driving me crazy! Does anyone have any ideas?

Related posts

Leave a Reply

1 comment

  1. The post excerpt takes the excerpt from the excerpt field in wordpress. By default the excerpt field is not shown on wordpress single posts/pages in the admin backend. You can add it by clicking the “screen options” in the top right of the “add new” post/page (or custom pages). You can then input any text you would like as the excerpt.

    As you can see by your var_dump, it is saying there is no excerpt in the post:

    " ["post_title"]=> string(14) "It Makes Sense" ["post_excerpt"]=> string(0).

    As stated before, the_excerpt() does not look for the excerpt in the main content body. If you don’t feel like adding the excerpt field in the back end, you can do something like this:

    $content = get_the_content(); echo substr($content, 0, 20);

    This will output the first 20 characters of the string (which is the content of the page/post/custom post). Obviously you can do 40 or something like that as well, to appropriately output what you feel is the rite amount.

    Happy coding!