0

I am trying to reproduce an existing site design in wordPress. The site has a sidebar navigation that shows 4 posts at a time, see here:

http://www.davidrich.net/david-rich-paintings/1-1

I you click the "next" link in the secondary nav, you will see that the images in the side navigation stay consistent until the next set of four posts. Each painting is in a separate post.

How can I display groups of four posts in the sidebar navigation?

I am really at a loss here, not sure where to begin. Any pointers would be much appreciated.

<?php 
$loop = new WP_Query( array( 'post_type' => 'paintings', 'posts_per_page' => 4, 'offset' => 0 ) );
$count = $loop->post_count; 
$number = ceil($count / 4);

echo "<ul>";
while ( $loop->have_posts() ) : $loop->the_post(); 
    if ( has_post_thumbnail() ) { 
        echo "<li>" . the_post_thumbnail() . "</li>";
    }  
echo "</ul>";
?>
1

I'm not sure if this is going to solve your whole issue, but you can add the paged parameter to your current custom query. I don't know why you have set the offset parameter. If your offset is 0, omit it completely

Also, remember to reset your post data after your custom query. Try something like this as a start and then work from there

<?php 
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$loop = new WP_Query( array( 'post_type' => 'paintings', 'posts_per_page' => 4, 'paged' => $paged ) );
$count = $loop->post_count; 
$number = ceil($count / 4);

echo "<ul>";
while ( $loop->have_posts() ) : $loop->the_post(); 
    if ( has_post_thumbnail() ) { 
        echo "<li>" . the_post_thumbnail() . "</li>";
    } 
endwhile;
wp_reset_postdata(); 
echo "</ul>";
?>

This should, in theory, page your custom query with your main query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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