Wordpress 中的自定义循环分页

Custom Loop Pagination in Wordpress

我在 wordpress 页面中使用这个自定义循环。它工作得很好(虽然它在这里被简化了)。但是,它会在一页上显示 100 个搜索结果。因为它是一个自定义循环,所以我正在努力让它使用一些分页(理想情况下每页 10 个)。有没有人以前做到过并愿意为我指出正确的方向?

非常感谢...

    <ul id="property-holder">
    <?php if ( $location_query->have_posts() ) :
    $row_counter = 0;

    while ( $location_query->have_posts() ) :
    $location_query->the_post();

    $date = get_field("availdate");
    $date = str_replace('/', '-', $date);
    $date = date('Y-m-d', strtotime($date));

    if ($date > $future) {
    $row_counter += 1;

    echo '<li id="property-item">';
    echo '<p>' . 'Test' . '</p>';
    echo '</li>';

    } 

    endwhile;

    else :

    echo 'No Results';
    endif; wp_reset_postdata(); ?>

    </ul>

    <nav>
    <?php previous_posts_link('&laquo; Previous 10 Results') ?>
    <?php next_posts_link('Next 10 Results &raquo;') ?>
    </nav>

我假设您已经像这样定义 $location_query $location_query = new WP_Query($args);,现在在您的参数中添加 posts_per_page => 10。这会将您的结果分成每页 10 个项目。如果您的分页没有在下一页显示新项目,请这样查询:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => 'your post type',
    'posts_per_page' => 10,
    'paged' => $paged
);
$location_query = new WP_Query($args);