wp_pagenavi does not work in Category.php

Asked

Viewed 295 times

0

I downloaded and installed the wp_pagenavi Plugin I put at the end of my code, it appears only not page, clicking, be in 2... 3... it does not page, always repeats the items 1 to 10.

Code

<?php get_header(); ?>
    <div class="contentCenter">
        <div class="internalContent">
            <h1> <?php echo "Categoria "; single_cat_title(''); ?> </h1>
            <?php query_posts($query_strings . "&order=ASC"); ?>

            <?php if(have_posts()) : while(have_posts()) : the_post(); ?>
                <div class="postList">
                    <div class="postListImage">
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                            <?php the_post_thumbnail(array(198, 198)); ?>
                        </a>
                    </div>
                    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                    <p style="font-size:12px; margin-top:4px;">
                        <i>Publicado por <strong><?php the_author(); ?></strong> em <strong> <?php the_time('d/m/Y'); ?></strong></i>
                    </p>
                    <?php the_excerpt(); ?>
                    <a href="<?php the_permalink(); ?>" id="read_more_link">
                        Continuar Lendo >>
                    </a>
                    <div class="visualClear"></div>
                </div>
            <?php
                endwhile;
                else:
            ?>
                <p class="no-posts-found">Nenhum post encontrado.</p>
            <?php
                endif;
            ?>
        <?php wp_pagenavi(); ?>
        </div>
    </div>
<?php get_footer(); ?>

What could I do to make it work?

Note: I am new to Wordpress.

2 answers

0

See if this sets the limit you want in line 5:

<?php
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
 $args = array('posts_per_page' => '8'); 
 query_posts($args . $query_strings . '&order=ASC&paged=' . $paged);
?>

0

wp_pagenavi is failing because your query is being overwritten with query_posts(). The Internet will tell you otherwise, but it’s never a good idea to use query_posts() because this function messes up all the global variables of the theme and causes these kinds of problems.

The plugin is implemented correctly but instead of calling query_posts in line 5 the changes in the query should be made in your file functions.php using the filter pre_get_posts.

Example:

add_action('pre_get_posts', 'modifica_query_category');
function modifica_query_category( $query ) {
    // modifica apenas a query principal de arquivos de categoria
    if ( $query->is_main_query() && is_category() ) {
        // altera a ordem para ascendente
        $query->set('order', 'ASC');
    } 
}

This eliminates duplicate query, improves site performance, and fixes pagination errors all at once :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.