WordPress搜索页面分页显示,但不起作用

时间:2018-07-17 作者:Carl Johnston

我有一个分页的搜索页面,显示了正确的页数,但是链接似乎正在转发到404页。

$paged = ( get_query_var( \'paged\' ) ) ? absint( get_query_var( \'paged\' ) ) : 1;
$search_args = array(
    \'posts_per_page\'    => 2,
    \'s\'                 => get_search_query(),
    \'post_status\'       => \'publish\',
    \'post_type\'         => \'post\',
    \'paged\'             => $paged,
);
$search = new WP_Query($search_args);
$big = 999999999; // need an unlikely integer
$pagination_args = array(
    \'base\'      => str_replace($big, \'%#%\', esc_url(get_pagenum_link($big))),
    \'format\'    => \'?paged=%#%\',
    \'current\'   => max( 1, get_query_var(\'paged\') ),
    \'mid_size\'  => 2,
    \'total\'     => $search->max_num_pages
);

echo paginate_links($pagination_args);
任何关于为什么这些链接可能被破坏的帮助都将是巨大的帮助!

1 个回复
SO网友:Carl Johnston

评论中提供的答案:

global $wp_query;
$big = 999999999; // need an unlikely integer
$pagination_args = array(
    \'base\'      => str_replace($big, \'%#%\', esc_url(get_pagenum_link($big))),
    \'format\'    => \'?paged=%#%\',
    \'current\'   => max( 1, get_query_var(\'paged\') ),
    \'mid_size\'  => 1,
    \'total\'     => $wp_query->max_num_pages
);
if(have_posts()):
    while(have_posts()):
        the_post();
        //individual search result
    endwhile;
    wp_reset_postdata();
    echo paginate_links($pagination_args);
endif;

结束

相关推荐

如何为class-wp-query.php追踪这些PHP通知和警告的原因?

我的WordPress调试。日志文件中充满了这些PHP通知,间隔大约15分钟,然后是几个小时…[23-Mar-2018 05:33:00 UTC] PHP Notice: Trying to get property of non-object in /home/mysite/public_html/wp-includes/class-wp-query.php on line 3736 [23-Mar-2018 05:33:00 UTC] PHP Notice: Trying to get p