小编Jan*_*ith的帖子

如何在自定义WP_Query Ajax上实现分页

我想用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)

此代码不分页.有一个更好的方法吗?

php ajax wordpress jquery pagination

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

ajax ×1

jquery ×1

pagination ×1

php ×1

wordpress ×1