【问题标题】:wordpress wp_query pagination not workingwordpress wp_query分页不起作用
【发布时间】:2021-05-31 18:52:36
【问题描述】:

这是我在主题index.php 上的代码。我正在使用二十个Twenty-One theme。我总共有 16 个帖子。我想每页显示 2 个带有分页的帖子,但此代码仅返回分页的前 2 页。它不会转到 page/3、page/4 等。

In WP dashboard->settings->Reading->Blog pages show at most is set to : 10 posts.
Your homepage displays is set to : Your latest posts

我想知道代码有什么问题?为什么这段代码不起作用?任何帮助将不胜感激。

get_header();

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
$the_query = new WP_Query('posts_per_page=2&paged=' . $paged );

if ( $the_query->have_posts() ) {

    
    while ( $the_query->have_posts() ) {
        $the_query->the_post();

        the_title(); // post Title
    }

    
    twenty_twenty_one_the_posts_navigation();
    
    wp_reset_postdata();

} else {

    echo 'now posts found';

}

get_footer();

【问题讨论】:

    标签: wordpress pagination


    【解决方案1】:

    如果您使用默认 index.php 并希望每页 2 个帖子,那么您可以轻松地使用管理员设置 2 而不是您已经知道的 10。我也检查了,你的代码几乎没问题,对我来说也很好,请用其他代码和其他东西调试它

    【讨论】:

    • 此代码对我不起作用。我无法浏览第三页。当我访问 /page/3 时,它显示“没有找到”。我还用其他主题尝试了上面的代码,但结果相同。你能导航到第三页吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    相关资源
    最近更新 更多