WordPress.org

Ready to get started?Download WordPress

Forums

pagination problem with last set (26 posts)

  1. tctc
    Member
    Posted 3 years ago #

    hi everyone... getting crazy with this issue:

    I have correctly implemented page navigation for my site and it works fine. Really good job! ;)
    The problem is that the last set of posts is not displaying correctly: it just mess up the style and "No articles" is written even if there are still 2 posts to display.
    It seems the pagination is not working if there are less than 10 posts to display (the query is set to display 10 posts max).

    The code of the page is:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    There are 2 loops inside the page. the primaty one which is paginated and the second one in the sidebar.

    Anyone has an idea why the last set of posts to display does not work? Please help! Already searched everywhere but without success!

  2. vtxyzzy
    Member
    Posted 3 years ago #

    You are passing the variable $additional_loop->max_num_pages to the paginate function. I do not see where that variable is set. I believe that this should be $wp_query->max_num_pages.

  3. tctc
    Member
    Posted 3 years ago #

    Thank you for the answer! I had a look in the function page where the pagination function is stored. There is the max_num_pages inserted this way:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Any idea? Please help... getting crazy!
    Thanks

  4. vtxyzzy
    Member
    Posted 3 years ago #

    You are not calling the function with the proper max_num_pages. Change this:

    <?php if (function_exists("pagination")) {
        pagination($additional_loop->max_num_pages);
    } ?>

    to this:

    <?php if (function_exists("pagination")) {
        pagination($wp_query->max_num_pages);
    } ?>
  5. tctc
    Member
    Posted 3 years ago #

    thank you!
    OK now it works but not completely. It misses the last 6 posts of the set. In total there are 26 posts under this category but the navigation finishes at 20 and not showing the other 6.
    ...
    Well... if you wanna have a look:

    http://www.snowboarditaliamag.it

    Try to go from the menu in MAGAZINE > RACCONTI

    thank you again!

  6. vtxyzzy
    Member
    Posted 3 years ago #

    Please delete the userid and password from above immediately!!

  7. tctc
    Member
    Posted 3 years ago #

    done! sorry.... there was user & oass for the accessing php directory....
    anyway...
    http://www.snowboarditaliamag.it/mag/racconti/page/3 this is the url which would be supposed to display the latest 6 posts of the 26... it is no working as you can see... with your changing now the link at the third (last) page isn't showed but latest 6 posts are missing...

  8. vtxyzzy
    Member
    Posted 3 years ago #

    I really can't tell anything from just looking at the site.

    Can you add a line under the query to show the number of posts found, like this:

    <?php global $query_string; query_posts($query_string . '&showposts=10' ); ?>
    <?php echo "FOUND POSTS: $wp_query->found_posts<br />"; ?>

    and see what it prints?

  9. tctc
    Member
    Posted 3 years ago #

    It writes 26 like the total number of posts in this category.
    It misses the last page where there are less than 10 posts. I think this is the problem which creates the page with "No articles"
    It happens for every categories whit this query and 'pagination' function...

  10. vtxyzzy
    Member
    Posted 3 years ago #

    I wonder if the pagination call needs to be before the 'else' part of if (have_posts()), like this:

    <!-- END LOOP -->
          <!-- PAGINATION FUNCTION -->
    
    <?php if (function_exists("pagination")) {
        pagination($wp_query->max_num_pages);
    } ?>
    
           <?php else: ?>
    <h2><?php _e('Nessun articolo presente'); ?></h2>
    <p class="center"><?php _e('Nessun articolo presente'); ?></p><?php endif; ?>
  11. tctc
    Member
    Posted 3 years ago #

    Well... just tried without success... I have tried both:

    <?php if (function_exists("pagination")) {
        pagination($wp_query->max_num_pages);
    } ?>

    in this case the last link to the last page containing the last 6 posts (out of 26) is not displayed...
    With this code:

    <?php if (function_exists("pagination")) {
        pagination($additional_loop->max_num_pages);
    } ?>

    the last link to the last page containing the last 6 posts (out of 26) is displayed but if clicked it does return "No article available" and the page does not show the last 6 posts....

    I'm getting creazy... such a strange behaviour... no idea.... :(

  12. vtxyzzy
    Member
    Posted 3 years ago #

    OK - please try a little more debugging. Print the max_num_pages like this:

    <?php global $query_string; query_posts($query_string . '&showposts=10' ); ?>
    <?php echo "MAX PAGES: $wp_query->max_num_pages<br />"; ?>
  13. tctc
    Member
    Posted 3 years ago #

    ok... the result is MAX PAGES: 2

    It is not correct: there are 6 posts missing which would make the third page with following url: ....../page/3

  14. tctc
    Member
    Posted 3 years ago #

    I've taken the function script that is currently used from this page:

    http://design.sparklette.net/teaches/how-to-add-wordpress-pagination-without-a-plugin/

  15. vtxyzzy
    Member
    Posted 3 years ago #

    The problem is that the query shows only 2 pages, so no matter which pagination function you use, it will only give 2 pages.

    Now, the question is "Why is the query only showing 2 pages?"

    Let's see what the $query_string is like:

    <?php global $query_string; query_posts($query_string . '&showposts=10' ); ?>
    <?php echo "QUERY STRING: $query_string<br />"; ?>
  16. tctc
    Member
    Posted 3 years ago #

    This is for the category with 26 posts:

    QUERY STRING: category_name=mag%2Feventi-contest

    This is another categoru with more or less 330 posts:

    QUERY STRING: category_name=mag%2Feventi-contest

    I found other relevant problem like if I use pagination($additional_loop->max_num_pages); then I get a certain number of links which are less than the supposed number of links that the number navigation should display... if i use: pagination($wp_query->max_num_pages); I get more number links but lasts of them does not work even if the number ok links which should be displayed is correct (like 33 for eventi-contest category which contains more or less 330 posts). But if I click link number 25 or 30 I get always the same error "No article sorry"......

  17. tctc
    Member
    Posted 3 years ago #

    And this is the result of the 17th page of the category with 330 posts:

    QUERY STRING: paged=17&category_name=mag%2Feventi-contest

  18. vtxyzzy
    Member
    Posted 3 years ago #

    I am sorry to have to do this, but I need to see the $wp_query. It will print a lot of data, but can you please leave it up for me to see?

    Be sure to put the line between the query and the if (have_posts()), like this:

    <?php global $query_string; query_posts($query_string . '&showposts=10' ); ?>
    <?php print_r($wp_query); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  19. tctc
    Member
    Posted 3 years ago #

    here you are and thanks a lot for that!

    [Query moderated as per the Forum Rules. Please use the pastebin in future. I've created a pastebin link for you this time.]

    http://wordpress.pastebin.com/pNW2ZNWk

  20. tctc
    Member
    Posted 3 years ago #

    all the content gave back from <?php print_r($wp_query); ?> is:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  21. vtxyzzy
    Member
    Posted 3 years ago #

    OK - you can take it out now. Do you see the problem? Look at the posts_per_page about half way down - it says posts_per_page => 20, not 10.

    Try changing from &showposts=10 to posts_per_page=10, like this:

    <?php global $query_string; query_posts($query_string . '&posts_per_page=10' ); ?>
  22. vtxyzzy
    Member
    Posted 3 years ago #

    Got to go to dinner now, back in 1 hour.

  23. tctc
    Member
    Posted 3 years ago #

    well... got to go sleep it's 1 o'clock here in Italy! Sorry for big pasting, didn't know about pastebin....
    I really really appreciate your help... I really have no idea on how to solve this problem, even if I've already solved all the problem with this site except this one...... :(
    I'll be back tomorrow morning...thank you very much again!

  24. tctc
    Member
    Posted 3 years ago #

    Incredible IT WORKS!!!!! but only if posts_per_page is set to 20 . I f I set it to 10 then there are the common problems explained before.... but it already a big step!
    Now the question is... how is it possible to set it to 10 posts without having the problems? Where is this problem?!?

    thank you a lot anyway... really good help! we miss a small step now!

  25. tctc
    Member
    Posted 3 years ago #

    Ok! Solved!! I had to change the configuration in Admin > Settings > Reading and set post to display to 10 like the number of posts_per_page !!

    I have to really thanks vtxyzzy for the precious help! THANKS A LOT!

  26. vtxyzzy
    Member
    Posted 3 years ago #

    Changing the Settings to 10 is just part of the problem. I think your theme is forcing all queries to the same number of posts per page. You may not want that.

    I tried to locate your theme to download it and look for the cause, but I could not find the theme. Can you post a link to its download site?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags