【问题标题】:wordpress - WP_Query, pagination not workingwordpress - WP_Query,分页不起作用
【发布时间】:2013-05-14 11:04:21
【问题描述】:

我正在尝试在我的WP_Query 中进行工作分页。 尝试超过 2 小时后,除了 stackoverflow 没有办法:-D。

我的问题是什么


较旧和较新的分页链接正在出现,当我点击它们时,它会将我带到正确的网址,即:/?paged=2

但是帖子列表没有改变,每个页面上的帖子都是一样的。

这是我的代码


$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

$args = array(
    'cat' => $cat,
    (($paged != '') ? 'paged =>'. $paged : ''),
    'posts_per_page' => $post_to_show 
);  

print_r($args);

$the_query = new WP_Query($args); 

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

     //post template            

endwhile;

if ( get_next_posts_link() || get_previous_posts_link() ) {
    echo '<div class="wp-navigation clearfix">
    <div class="alignleft">'.next_posts_link('&laquo; Older Entries').'</div>
    <div class="alignright">'.previous_posts_link('Newer Entries &raquo;').'</div>
    </div>';
}


wp_reset_query();

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    您的 $args 数组看起来有问题。此外,$paged 永远不会为空(因为它总是被分配默认值 1),因此您的检查是多余的。

    1 作为页码传递并没有错。

    $args = array(
        'cat' => $cat,
        'paged' => $paged,
        'posts_per_page' => $post_to_show 
    );  
    

    【讨论】:

    • 但 print_r 显示正确的页码:Array ( [cat] =&gt; 14 [0] =&gt; paged =&gt;2 [posts_per_page] =&gt; 12 )
    猜你喜欢
    • 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
    相关资源
    最近更新 更多