如果您添加了pagination()
功能到您的functions.php
, 您只需在主题文件中调用它。哪个文件取决于要显示它的位置,请参见the Template Hierarchy 有关详细信息。
您不想在循环内部调用此while () {}
或while : ... endwhile;
), 因为这将再次为每个帖子显示它。是否在search.php
或loop-search.php
取决于你的个人喜好。二十点十分in the loop*.php
files. 总结一下,它看起来是这样的:
<!-- Display pagination links above the posts -->
<?php pagination(); ?>
<!-- Display the posts -->
<?php if(have_posts()) { while(have_posts()) { the_post();?>
<!-- Some details for this post -->
<!-- End the loop -->
<?php }} /* if, while */ ?>
<!-- Display pagination links again below the posts -->
<?php pagination(); ?>
我建议您在
pagination()
具有更独特的功能。你永远不知道WordPress什么时候会包含一个名为
pagination()
它本身
dan_pagination()
是一种可能的替代方案:-)
网上有许多分页教程,其中许多都有不准确之处。链接到的教程也是如此。它不会使用当前查询的帖子总数,而是统计博客中的所有帖子,以确定页面数。这将在搜索页面上显示错误。我会这样更改函数的开头:
function wpse18805_pagination( $scope = 2 ) {
global $wp_query;
$numPages = $wp_query->max_num_pages;
$curPage = $wp_query->get( \'paged\' );
if ( ! $curPage ) {
$curPage = 1;
}
// page bounds ... continue from there
此功能还将生成始终从博客底部开始计数的链接,因此它不适用于搜索页面。要解决此问题,请在
// echo the link
使用:
echo \'<li><a href="\' . get_pagenum_link( $page ) . \'">\' . $page . \'</a></li>\';