Forums

Show thumbnails for posts, but not for the post your on (3 posts)

  1. devotee
    Member
    Posted 1 year ago #

    I´m making a portfolio-style theme where I´m looping in thumbnails from other posts in the same category, under the content of the single post. However, I would like to exclude the post you´re currently reading from the thumbnail listing. Anyone knows how I could do that?

    This is what my current loop looks like:

    http://pastebin.com/hJ3k1rW6

  2. Digital Raindrops
    Member
    Posted 1 year ago #

    Outside the loop

    <?php $postid = $post->ID; ?>

    Inside the loop

    <?php if ( ($post->ID != $postid ) && has_post_thumbnail() ) :?>

    HTH

    David

  3. alchymyth
    The Sweeper
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/WP_Query#Post_.26_Page_Parameters

    'exclude' might not be the right/valid parameter; try 'post__not_in':

    change from this:
    'exclude' => $post->ID
    to this:
    'post__not_in' => array($post->ID)

    ---
    to get only posts with thumbnails, you can try and add this to the query parameters:
    'meta_key' => '_thumbnail_id'

    (or try:
    'meta_query' => array(array('key' => '_thumbnail_id'))
    (untested)
    http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters
    )

Topic Closed

This topic has been closed to new replies.

About this Topic