我想用Ajax在自定义循环中对我的WordPress帖子进行分页,所以当我点击加载时会出现更多按钮帖子.
我的代码:
<?php
$postsPerPage = 3;
$args = array(
'post_type' => 'post',
'posts_per_page' => $postsPerPage,
'cat' => 1
);
$loop = new WP_Query($args);
while ($loop->have_posts()) : $loop->the_post();
?>
<h1><?php the_title(); ?></h1>
<p>
<?php the_content(); ?>
</p>
<?php
endwhile;
echo '<a href="#">Load More</a>';
wp_reset_postdata();
?>
Run Code Online (Sandbox Code Playgroud)
此代码不分页.有一个更好的方法吗?