admin管理员组文章数量:1334167
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?
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?
Share Improve this question edited Sep 28, 2012 at 17:45 Rarst 100k10 gold badges161 silver badges298 bronze badges asked Sep 28, 2012 at 17:39 swtshwetaswtshweta 4326 silver badges16 bronze badges2 Answers
Reset to default 1Soumitra 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
.
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.
本文标签: What is the best way to implement ajax based pagination on custom query based templates
版权声明:本文标题:What is the best way to implement ajax based pagination on custom query based templates? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742365329a2461163.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论