Ending Pagination loop in PHP

时间:2013-02-26 作者:Monstr92

<div id="pagination">
    <div class="prev"><?php next_posts_link(\'&larr;\') ?></div>
    <div class="pages">
        <?php
            global $wp_query;
            $big = 9999;
            echo paginate_links(array(
                \'base\' => str_replace($big, \'%#%\', get_pagenum_link($big)),
                \'format\' => \'?paged=%#%\',
                \'total\' => $wp_query->max_num_pages,
                \'current\' => max(1, get_query_var(\'paged\')),
                \'show_all\' => false,
                \'end_size\' => 1,
                \'mid_size\' => 5,
                \'prev_next\' => false,
                \'prev_text\' => \'Prev\',
                \'next_text\' => \'Next\',
                \'type\' => \'list\'
            ));
        ?>
    </div>
    <div class="next"><?php previous_posts_link(\'&rarr;\') ?></div>
</div>
您好,我有一个分页循环设置,正在选择显示数字和上一个/下一个链接。然而,我正在试图找出如何在最近的5篇文章[1,2,3,4,5]中结束#\'s,而不是将其延续到[1,2,3,4,5,6,7]。在我博客上最近发表的5篇文章中,我将如何结束它?

“我只是想编辑div class pages部分,使其仅以5结尾。”-如果这有意义的话。

Screenshot

1 个回复
SO网友:birgire

你可以试试

\'total\' => min(5,$wp_query->max_num_pages),

Edit:

在源代码中paginate_links

http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/general-template.php#L1922

链接显示在循环中$n = 1; $n <= $total; $n++ 从那以后%#% 替换为$n 我的想法是通过限制$total 至少达到5$wp_query->max_num_pages. 希望这有帮助;-)

结束

相关推荐

Pagination on custom query

我正在使用以下代码query_posts 要组合自定义搜索,请执行以下操作:$args = array( \'post_type\' => \'species\', \'meta_query\' => $meta_query, \'tax_query\' => $tax_query ); $meta_query 由以下几段代码组成:if (!empty($_POST[\"s_aquarium_H\"])) {