• Resolved jzk

    (@jzk)


    Hello everyone!

    On my homepage, I’m displaying the content from the category called “News” for this I’m using :

    <?php
            //The Query
    	query_posts('posts_per_page=10&cat=-80');
            //The Loop
    	if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    I added the plugin WP_Pagenavi to display the next articles from the category “News” on my homepage layout like this :

    <?php endwhile; ?>
                  <?php wp_pagenavi(); ?>
    	<?php endif; ?>

    So when I click on the link page 2 for instance, the site display the URL https://www.example.com/page/2 but the content doesn’t change, still the same homepage.

    Do you have ideas how to fix this ?

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jzk

    (@jzk)

    FYI, I found how to resolve this problem like this :

    <?php
      $temp = $wp_query;
      $wp_query= null;
      $wp_query = new WP_Query('cat=-6&paged=' . $paged);
      while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>
    
    <?php // the usual post-displaying codes here ?>
    
    <?php
      endwhile;
      if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
      $wp_query = null; $wp_query = $temp; ?>

    Sources= https://www.wplover.com/756/how-to-get-custom-wp_query-loop-working-with-pagination-and-wp-pagenavi

    Thanks!

    hey !

    I tried this solution but it doesn’t work for me

    cheers

    Hi,

    I’m not sure if this still needs attention but I know a solution.

    WordPress uses a variable named paged to know on what page the query is made. If we are on the second page of an iteration of posts, then paged will be set to 1(maybe 2, depending if the pages are 0 based or not).

    By default, the URL for a second page of iteration would look like this: https://www.example.com/paged=X where X is the page number.

    This variable can be set into query posts or WP_Query. Simply adding paged=get_query_vars(“paged”) will solve the problem.

    Example
    query_posts('posts_per_page=10&cat=-80&paged='.get_query_vars("paged"));

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Loops and WP PageNavi Plugin problems’ is closed to new replies.