0

We can use multiple plugins like wp-pagenavi or wp-paginate for implementing pagination for wordpress sites and making it ajax based using the following code:

jQuery(document).ready(function(){
    // ajax pagination
    jQuery('#wp_page_numbers a').live('click', function(){ 

        var link = jQuery(this).attr('href');                   
        jQuery('#main').html('Loading'); 
        jQuery('#main').load(link+' #entries')
    });
}); // end ready function

Sometimes, there are some cases where we want to display results based on custom query (i.e fetching results from the tables other than wordpress default tables) on a page template.

What is the best way for implementing pagination in this case?

1

Soumitra Chakraborty wrote a very good tutorial on Getting Started with AJAX & WordPress Pagination. I would recommend following that pattern (in terms of how to use admin_ajax.php in conjunction with your functions.php.

That tutorial will give you a great framework for how to implement ajax pagination by hand.

In terms of your own specific requirements for a custom query (which it sounds like might involve getting data from non-standard tables) you can use the WP_Query class to do some pretty advanced stuff (like what you describe) in your custom function that you define in functions.php.

| improve this answer | |
  • Thanks for providing this article Jared. I'll try to implement ajax using these steps now. – swtshweta Oct 2 '12 at 3:05
0

I have just find a simple solution where I have tried several "advanced" and modern frameworks, but old reliable jquery make it simple.

$(document).ready(function(){
// ajax pagination

$('#paginator a').on('click', function(e){ 
    e.preventDefault();
    console.log('paginate');
    var link = $(this).attr('href');
    $('.current').removeClass('current');
    $(this).addClass('current');
    $('#main-content').html('Loading');

    $('#blog').load(link+' #main-content');
    $('#paginator').load(link+' .pagination') 
});

});

I just add some minor variations in order to update the post grid, in my case main content. and pagination status in my case #pagination. Both with an inner div to just update what is being modified.

| improve this answer | |

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.