Forums

[resolved] Loops and WP PageNavi Plugin problems (4 posts)

  1. jzk
    Member
    Posted 1 year ago #

    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 http://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!

  2. jzk
    Member
    Posted 1 year ago #

    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= http://www.wplover.com/756/how-to-get-custom-wp_query-loop-working-with-pagination-and-wp-pagenavi

    Thanks!

  3. jeremie85
    Member
    Posted 1 year ago #

    hey !

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

    cheers

  4. agilius
    Member
    Posted 1 year ago #

    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: http://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"));

Topic Closed

This topic has been closed to new replies.

About this Topic