我在搜索中使用这个。php模板…
<div class="pagination">
<?php echo get_pagination_links(); ?>
</div>
这是函数…function get_pagination_links() {
global $wp_query;
$big = 999999999;
return paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', esc_url( get_pagenum_link( $big ) ) ),
\'format\' => \'?paged=%#%\',
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $wp_query->max_num_pages,
\'prev_next\' => false
) );
}
-输出有效:如果我搜索“test”,结果超过10个,分页显示1 2
哪里2
是一个链接。单击页面时2
地址栏正确更新为mysite.com/search/test/page/2
但生成的页面仍然是数字1
.
仍有与页码相同的结果1
分页链接仍然相同-2
仍然是链接和1
是当前页。
你知道为什么会这样吗?
Update
以下是在模板中调用自定义函数的位置:<?php
/**
* The template for displaying Search Results pages
*/
get_header(); ?>
<?php if ( have_posts() ) : ?>
<hgroup class="section-heading wrapper">
<h1>Results</h1>
</hgroup>
<section id="results">
<?php while ( have_posts() ) : the_post(); ?>
<ul class="event-items">
<?php get_template_part( \'inc/search\', \'result\' ); ?>
</ul>
<?php endwhile; ?>
</section>
<div class="pagination tiny wrapper">
<?php echo get_pagination_links(); ?>
</div>
<?php else : ?>
<div class="wrapper">
<h2>Nothing found</h2>
</div>
<?php endif; ?>
<?php get_footer(); ?>
使用以下答案中的推荐代码编辑:/**
* Pagination links for search and archives
*/
function get_pagination_links() {
global $wp_query;
$wp_query->query_vars[\'paged\'] > 1 ? $current = $wp_query->query_vars[\'paged\'] : $current = 1;
$big = 999999999;
return paginate_links( array(
\'base\' => @add_query_arg(\'paged\',\'%#%\'),
\'format\' => \'?paged=%#%\',
\'current\' => $current,
\'total\' => $wp_query->max_num_pages,
\'prev_next\' => false
) );
}
分页现在正在工作,但是“永久链接”并不是我想要的那样。我使用custom_pagination_base()
要拥有此permalink结构:mypage.com/search/term/seite/2
(其中seite是德语中page的单词)mypage.com/search/term?paged=2