wordpress pagination with query posts

wordpress pagination with query posts, Mostly people use query_posts function for fetching posts. But most of all people face issue with pagination.

wordpress pagination with query posts

Just use following code for pagination. It is simple and easy.

<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts( 'post_type=documents&paged='.$paged );
query_posts( 'post_type=post&paged='.$paged );
if (have_posts()) : while (have_posts()) : the_post(); ?>

<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
<?php the_excerpt();  ?>

 <?php endwhile; ?>
<div id="nav-below" class="navigation">
                                        <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
                                        <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
                                </div><!-- #nav-below -->
                                  <?php endif; wp_reset_query(); ?>

wordpress pagination with query_posts
wordpress pagination with query_posts

add ajax pagination in wordpress blog

For without refresh the data from home page if you want to show the pages and pagination in wordpress blog than you can use the following code for add ajax pagination in wordpress blog.

add ajax pagination in wordpress blog

With the help of jquery you can easily add the pagination wordpress blog site. You just need to add the following code into header.php file.

[viral-lock message=”Source code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php wp_enqueue_script('jquery'); ?>
<script>
jQuery(document).ready(function(){
 // ajax pagination
 jQuery('#wp_pagination a').live('click', function(){ // if not using wp_pagination, change this to correct ID
 var link = jQuery(this).attr('href');
 // #main is the ID of the outer div wrapping your posts
 jQuery('#main-container').html('<div><h2>Loading...</h2></div>');
 // #entries is the ID of the inner div wrapping your posts
 jQuery('#main-container').load(link+' #entries')
 });
}); // end ready function
</script>

[/viral-lock]

just put above code in header.php file in head section. Just make sure that you are putting above code after wp_head function.

add ajax pagination in wordpress blog
add ajax pagination in wordpress blog

If you are not wordpress developer then dont use following code and If you are facing any issue then write to me on support@purabtech.in