如何将查询字符串追加到分页?

时间:2014-02-12 作者:Keith Donegan

我想在我的循环中添加第2页之后的2个变量。

This is my normal category page

www.example.com/category/news/

This is what I would like on pages: 2, 3, 4, 5 etc

www.example.com/category/news/page/2/?var1=one&var2=two
循环:

$args = array
(
   \'category_name\' => \'news\',
   \'posts_per_page\' => 5,
   \'paged\' => $paged
);

$news_loop = new WP_Query($args);
while ($news_loop->have_posts()) : $news_loop->the_post();

    // posts

endwhile;
wp_pagenavi(array(\'query\' => $news_loop)); ?>

1 个回复
SO网友:Sudeep K Rana

请参阅:Paginate Codex

我可以看到您正在使用自定义查询,所以您将其放在while循环的下面和外部

<?php
        global $wp_query;
        $big = 999999999; // need an unlikely integer
        $args = array(
            \'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
            \'format\' => \'?page=%#%\',
            \'total\' => $wp_query->max_num_pages,
            \'current\' => max( 1, get_query_var( \'paged\') ),
            \'show_all\' => true,
            \'end_size\' => 1,
            \'mid_size\' => 2,
            \'prev_next\' => False,
            \'prev_text\' => __(\'&laquo; Previous\'),
            \'next_text\' => __(\'Next &raquo;\'),
            \'type\' => \'list\',
            );
        echo paginate_links($args);
    ?>

结束

相关推荐

Several loop in search result

我想在搜索后的结果中使用两个循环。首先,如果有结果,我开始循环<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> 并在循环后显示属于某个类别的文章<?php $cats = get_categories(); foreach ($cats as $cat) { query_posts(\'cat=\'.$cat-&g