• hello,
    i’m developing a custom template in which I included wp_pagenavi and it seems to be working when called via the category.php template.

    The strange thing (that might be connected to my complete noobishness in developing themes) is that when passing to another page clicking on one of the links produced by wp_pagenavi, the called template is not category.php anymore but index.php.

    here is the code (posted in case anyone can immediately note some terrible mistake)

    function bloglist() {                                                                                                                       
    
    global $wp_query;
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    
    $args=array(
            'posts_per_page'=>'1',
            'paged'=>$paged,
            'order'=>'desc',
            'orderby'=>'date',
            'type'=>'post',
            'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash'),
            );
    $the_query = new WP_Query( $args );
    
    // tot post per testing
    //$posttotali=$the_query->found_posts;
    //echo $posttotali;
    
    // Il Loop
    while ( $the_query->have_posts() ) :
            $the_query->the_post();
    
            //categoria
            $categories = get_the_category();
            if ( ! empty( $categories ) )
                    $cat='<li>CATEGORIA: <a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]-
    
            //thumbnail
            /*
            $thumbnail = (has_post_thumbnail()) ? 
                    get_the_post_thumbnail('thumbnail', array('class'=>'img-responsive')) : 
                    '<img class="img-responsive" src="images/img_post.jpg" alt="">';
            */
    
            echo '<article>
                                    <div class="col-sm-5 img_post_list">
                                    <a href="'.get_permalink().'">
                                            '.get_the_post_thumbnail($post_id, 'thumbnail', array('class'=>'img-responsive')).'
                                    </a>
                                </div>
                                
                                <div class="col-sm-7 info_post_list">
                                        <h2><a href="'.get_permalink().'">'.get_the_title().'</a></h2>
                                        <p>'.get_the_excerpt().'</p>
                                        <ul class="list info_post pull-left">
                                            <li>PUBBLICATO: <span>'.get_the_date().'</span></li>
                                            '.$cat.'
                                        </ul>
                                        <a class="btn btn-success btn-sm pull-right" href="'.get_permalink().'">Leggi tutto</a>
                                </div>
                            </article>';
    
    endwhile;
    
            echo '<div class="text-center">'.wp_pagenavi( array( 'query'=> $the_query)).'</div>';
            //echo '<div class="text-center">'.wpbeginner_numeric_posts_nav().'</div>';
            
    
    // Ripristina Query & Post Data originali
    wp_reset_query();
    wp_reset_postdata();
    
    }

    After that I obvioulsy recall the bloglist() among the html which on the first page seems to be working correctly.

    Thanks in advance for any help

  • The topic ‘wp-pagenavi calls index.php instead of category.php with paged greater than 1’ is closed to new replies.