简体   繁体   中英

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() . 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:

 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?

As suggested in the comments above, remove the query_posts stuff from tag.php and modify the query from 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM