All ‘featured thumbnails’ appear in every post excerpt. (3 posts)

  1. Gemma Wild
    Posted 4 years ago #

    All ‘featured thumbnails’ appear in every post excerpt.

    I have 3 published posts on my front page (it’s a test site so I cannot include a link), one on top of the other. I have Advanced Excerpt installed and the following code (copied from the WordPress Codex and from a forum post helping me remove the default <p> tag from excerpts). I’m also only calling the loop once and that’s within the page template (as shown below).

    Everything works nicely and looks how it should apart from the fact that each post has the thumbnail of the other posts within it, instead of just its own!

    So if I publish 2 posts, I get 2 thumbnails per excerpt, 3 posts = 3 thumbnails per excerpt, 5 posts = 5 thumbnails per excerpt, and so on. I only need the 1 correct thumbnail that’s attached to post to appear.

    Can anyone help me with this? I was going to have the most recent post on the first page (which would work fine as its only 1) but also use this code for my blog page (instead of a plugin) which would have many posts resulting in x amount of thumbnails per excerpt.

    Here's the code I use in my template:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. Michael
    Forum Moderator
    Posted 4 years ago #

    where is that section coming from:

    $thumbnails = get_posts('numberposts=5');
    foreach ($thumbnails as $thumbnail) {
    if ( has_post_thumbnail($thumbnail->ID)) {
    echo '<a href="' . get_permalink( $thumbnail->ID ) . '" title="' . esc_attr( $thumbnail->post_title ) . '">';
    echo get_the_post_thumbnail($thumbnail->ID, 'blog-thumbnail-small', array('class' => 'content_main_blog_thumb'));
    echo '</a>';

    this basically grabs the latest five posts, and shows the thumbnails for these five posts - so will always have up to five the same thumbnails above the exerpt.

    start by removing the section.

    simply use <?php the_post_thumbnail(); ?>


    I answered a topic with the same rubbish code yesterday - see this for more details: http://wordpress.org/support/topic/same-featured-image-appearing-in-every-post-on-the-front-page?replies=5

  3. Gemma Wild
    Posted 4 years ago #

    @alchymyth - That was really helpful and exactly what I was after, thank you! I did do a search before posting but didn't manage to come across your post.

    The only question I have now is how to include only 1 recent post on the home page as its currently displaying as many as I have published? Baring in mind that on my actual blog page, I will display x amount per page (probably 10).

    Anyone else having this problem who finds my post, please read this:


Topic Closed

This topic has been closed to new replies.

About this Topic