Skip to main content

Insert a Paged Blog Loop anywhere in your WordPress theme

[code]
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query(‘post_type=post&posts_per_page=5′.’&paged=’.$paged); ?>

have_posts()) : $wp_query->the_post();?>


[/code]
Note that the <?php bootstrap_pagination();?> function has already been discussed in our post “Add Twitter Bootstrap Pagination to your WordPress Theme“.

I won’t spend too much time explaining this one. Just know that this will start an independent loop of your choice anywhere you want in your theme templates. And it correctly incorporates wp’s pagination feature, which can be tricky. I primarily use this code in a template I call blog.php. Many clients want either a static home page, or magazine-style home page, but still want a blog-reel displayed elsewhere (a la the common index.php). My blog.php template featuring the above code can be easily added to any internal page of their choice. Of course, there are countless ways to customize the query parameters.

Doug

Doug is an experienced project leader who strives to keep our clients' projects flowing smoothly. As a Developer, Doug is able to ensure a high level of customer satisfaction by focusing his efforts on the setup & support of content management systems (i.e. WordPress & Drupal), custom theme development, CSS/HTML coding, and graphic design. When Doug is not working on web projects, he can be found performing with several professional bands around San Diego.

Leave a Reply

Your email address will not be published. Required fields are marked *