您需要使用AJAX请求加载接下来的10篇文章,并将当前偏移量存储在DOM中。
将ID附加到<span>
元素,它是您的按钮,在我的示例中,我使用了#load_posts
.
然后使用jQuery,您可以轻松地为按钮设置click事件以触发AJAX请求。
所以按钮:
<span class="ar-bottom-link-tabs" id="load_posts">
<span>
<a href="#">Load more »</a>
</span>
</span>
然后在循环外部的下面添加jQuery:
<script type="text/javascript">
// We have already loaded 10 posts, so set it up as 10 by default
var currentOffset = 10;
var categoryId = 8;
$(\'#load_posts\').bind(\'click\', function(e){
// Stop the link reloading the page
e.preventDefault();
// Asign variables to an array
var data = {
offset: currentOffset,
catid: categoryId
};
// AJAX $_POST request to PHP file
$.post(\'path_to_php_file.php\', data, function(response) {
// do something with the response... loop through and append to the tab content
// so you could return the output as JSON
// Add 10 to the offset
currentOffset+10;
});
});
</script>
然后,在用于AJAX请求的PHP文件中,只需重复get\\u posts()调用:
$args = array(
\'cat\' => $_REQUEST[\'catid\'],
\'offset\' => $_REQUEST[\'offset\'],
\'showposts\' => 10
);
$posts = get_posts($args);
我会让你填补空白,但这会让你朝着正确的方向前进。