0

The idea is - when a user is viewing a post, he has the thumbnails of all the other posts in the bottom or something like that.

It sounds simple at first but what I'm looking for is something similar to fancybox thumbs http://fancyapps.com/fancybox/demo/ click in a image where it says "Thumbnail helper".

Basically my Wordpress posts are nothing more than images. I'm making a Wordpress gallery. So if a user clicks on a image, I don't want fancybox. I want him to be redirected to the post (image) page and there he'll have the remaining posts thumbs and he can navigate through them, considering that everytime he changes a post, it'll be updated on the thumbs. Pretty much what happens with fancybox.

Is this even possible? Is someone familiar with this?

Thanks.

1 Answer 1

1

You would have to get all the posts but the current one with a wp_query then loop through them and output their thumbnail.

Something like this (Should work but untested)

<?php
//Set the current page id
$current_id = get_the_id();

// Get all posts of a post type but the current post
$the_query = new WP_Query( array(
    'post_type' => 'your-post-type',
    //'post__not_in' => array( get_the_id() ), Removed to include current post
    'posts_per_page'=>-1
) );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        if( $current_id  == get_the_id() ){
            $current = 'active';
        } else {
            $current = '';
        }
        echo '<a class="'.$current.'" href="'.get_permalink( get_the_id() ).'">';
        echo get_the_post_thumbnail( get_the_id() );
        echo '</a>';
    }
    echo '</ul>';
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();
?>

EDIT: added 'posts_per_page'=>-1 to the query args

EDIT2: Show the current post with a class of active

6
  • It's working! But it's only showing 3 extra post thumbs and they're random. Also there's no problem in showing the current post thumb! It should be something like the current post thumb in the middle, the newer to the left (or right or top or whatever) and the older to the opposite side. And perhaps having a way to specify how many I wanna show in both sides. Do you think it's possible? Commented Sep 17, 2014 at 11:32
  • See my amended code, you nee 'posts_per_page'=>-1 to get all the posts, you can pass that what ever you want to get how many, but it will get them from latest to oldest unless you define the order. See the documentation for full order details Commented Sep 17, 2014 at 11:35
  • Gotcha. And how exactly do I put the current in the middle? Commented Sep 17, 2014 at 11:37
  • I updated the code so it should now show the current post in the others with a class of active so you can style it up. Commented Sep 17, 2014 at 11:43
  • You're the man! I thought it'd be much harder. Thanks! Commented Sep 17, 2014 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.