WordPress built in with many query method, our example below about query is the best way to create Multiple Loops. I will show you how to do multiple loops in wordpress. let us assume we want to have two lists of posts. One which would list the most recent posts (the standard 10 posts most recently added), and another which would contain only one post from the category ‘featured’. Posts in the ‘featured’ category should be shown first, followed by the second listing of posts (the standard).
Step 1. Get only one post from the ‘featured’ category.
<?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
<!-- Your First Looping Code will be here -->
<?php endwhile; ?>
This query is set $my_query equal to the result of querying all posts where the category is named featured and by the way, get me one post only. Also, set the variable $do_not_duplicate equal to the ID number of the single post returned. Recall that the Do stuff line represents all the formatting options associated for the post retrieved.
Note that we will need the value of $do_not_duplicate in the next step to ensure that the same post doesn’t appear in both lists.
Step 2. The second loop, get the X latest posts (except one).
This code below will be do some query except the one post that has been displayed on the first query..
<?php if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?> <!-- Your Second Looping Code will be here --> <?php endwhile; endif; ?>
That code will be displayed latest post except 1 post that has been displayed on the first loop. So the completed code will be like this
<?php $my_query = new WP_Query('category_name=featured&posts_per_page=1');
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<!-- Looping Code -->
<?php endwhile; ?>
<!-- Do other Loop -->
<?php if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<!-- Looping Code -->
<?php endwhile; endif; ?
I hope this tutorial how to setup multiple loops in WordPress blog is clearly for you and have a nice day, with this tutorial, we can create unique page templates. We can added extra query in our Page Template.



Pingback: How To Create "Dynamics Statics" Pages on WordPress # WordPress Tricks & Tips
Pingback: How To Create “Dynamics Statics” Pages | Silver Blog
Pingback: How To Create “Dynamics Statics” Pages | Unlock IMEI Cellphones
Hi,
thanks for this wonderful post! As a designer (with a very small knowledge of php) I found it very clear and complete.
I have a problem: I’ve used your suggestion in the homepage of http://www.recruitingclub.at but there’s a small problem. When you go to the older articles (“Ältere Artikel” at the bottom of the page), you still get the 2 latest articles. Do you know how to do to show a personalized loop only in the first page of a pagination?
Thanks a lot!
Thanks! This is what I have been looking for. Don’t forget the closing “>” on the completed code view.
I am planing to customize my blog, This article would be very helpful.
Thank you.
Sudeep