[英]WordPress page navigation not working on tag.php
I'm trying to add pagination to my tag.php file in WordPress, to get it working I used wp_pagenavi()
. 我正在尝试将分页添加到WordPress中的tag.php文件中,以使其正常工作,我使用了wp_pagenavi()
。 I have set the $paged
variable but for some reason when I click on page 2 it takes me to a broken page, attempted code: 我已经设置了$paged
变量,但是由于某些原因,当我单击页面2时,它会将我带到一个损坏的页面,尝试执行代码:
global $query_string;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('posts_per_page=6&tag='.$current_tag."&paged=".$paged );
while (have_posts()) : the_post();
/* LOOP STUFF */
endwhile;
wp_pagenavi();
wp_reset_query();
endif;
How can I get tag.php to go to page 2? 如何获得tag.php转到第2页?
As suggested in the comments above, remove the query_posts
stuff from tag.php
and modify the query from functions.php
: 如以上注释中所建议,从tag.php
删除query_posts
东西,并从functions.php
修改查询:
add_action( 'pre_get_posts','so16299109_pre_get_posts' );
function so16299109_pre_get_posts( $query )
{
if( is_tag() && $query->is_main_query() ){
$query->set( 'posts_per_page', 6 );
}
return $query;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.