• I selected a Posts Page from the Reading Settings on which to display my posts. Now in my index template I’m having trouble showing the page thumbnail above all the posts.

    My code is

    <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>
                  <?php the_post_thumbnail( 'page_thumbnail' ); ?>
                   <?php endwhile; ?>
         <?php endif; ?>
    
    and below is a query posts loop that lists my posts from a certain category..

    Above the list of recent posts, instead of showing just the one page thumbnail it shows a list of them from random posts. I’m not sure how to call the page thumbnail without generating a list. Not sure what’s missing..Is there some kind of solution for this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m not quite sure what you want, but if you only want one thumbnail from the most recent post, try this (UNTESTED):

    <?php $my_query = new WP_Query('posts_per_page=1');
    if ($my_query->have_posts()) :
       while ($my_query->have_posts()) : $my_query->the_post();
          the_post_thumbnail( 'page_thumbnail' );
       endwhile;
    endif;
    wp_reset_query();
    ?>
    Thread Starter nemci7v

    (@nemci7v)

    Thanks for the reply! I’m trying to display the thumbnail of the page, not post. But I have posts on the page as well and they;re interfering. I’m not sure how to separate both loops.

    Thread Starter nemci7v

    (@nemci7v)

    Ok, I tired your code as well. It retrieves the post thumbnail from another post.

    This works with a custom page template but not on an index page..

    Have you tried just inserting the image into the page and using the_content() in the first loop?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Showing the post thumbnail on Posts Page’ is closed to new replies.