I'm looking for some advice on how to make a gallery of images. it is a particular bit a gallery, because I would show the last 5 post and a fixed post, for a total of 6 posts, in a specific order. ie the fixed post must be the third in the list. The only method that I believe it is possible to create 3 loops, the first to see the last two post, the second to display the fixed post (by id), and the third to see other last three posts. Something like this (most probably it is not correct):
<?php $my_query = new WP_Query( 'posts_per_page=2' ); // get the latest 2 posts while ( $my_query->have_posts() ) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?> <?php the_title(); ?> <?php endwhile; ?> <?php $my_query2 = new WP_Query( 'p=1' ); // get fixed post with id=1 while ( $my_query2->have_posts() ) : $my_query2->the_post(); ?> <?php the_title(); ?> <?php endwhile; ?> <?php $my_query3 = new WP_Query( 'posts_per_page=3' ); // get the latest 3 posts while ( $my_query3->have_posts() ) : $my_query3>the_post(); if ( $post->ID == $do_not_duplicate ) continue; // don't show the same post of the first loop ?> <?php the_title(); ?> <?php endwhile; endif; ?>
There's a different way to do this without do many loops, considering that there's already one in the page ?