wordpress-logo

I have customized my WordPress home page. Few days ago i found that the next and previous page links are not working properly i try to solve it and finally found a solution on wordpress website. To solve wordpress page links problem read below:

When we use query_post() to exclude or include some posts of specific categories then the pagination of wordperss doesn’t work. It will show same posts on every page as home page.

The problem is query_posts() function overrides nearly everything in the standard posts object query, including paged offset is.

For proper pagination with query_posts(). Use the following code:

Existing Code:
<?php if(have_posts()) : ?>
    <?php query_posts("category_name=CategoryName"); ?>
        <?php while(have_posts()) : the_post(); ?>  

Replace With:
<?php if(have_posts()) : ?>
     <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
     query_posts("category_name=CategoryName&paged=$paged"); ?>
        <?php while(have_posts()) : the_post(); ?>

You are done!

Instead of using query_post() functionTheir is another solution to exclude or include posts of different categories from wordpress home, archive of other pages you can use “Advance Category Excluder” plugin of wordpress. Its very simple and easy to use plugin to perform such tasks.

Advertisement

22 Responses to “WordPress Next/Previous Page Links Problem – query_post Pagination Problem”

  1. Thanks for the solution! I’ve been struggling to get pagination to work on my new site and now it’s fixed!
    Cheers mate

  2. Thanks! Worked for me to solve WordPress Next/Previous Page Links Problem (query_post Pagination Problem)

  3. Awesome solution for page links problem – thanks so much!

  4. You’re a life saver! I spent so much time trying to fix this, and then your post appeared!

    THANK YOU

  5. This is awesome. Took me just 5 minutes to fix. Maybe it’ll be good to highlight that users still need to replace the “CategoryName” variable as it got me stumped for awhile. Thanks!

  6. Brilliant.

    Thanks for this great tip, helped me sort this out in 2 mins

  7. Thanks for this – I was very stuck and you’ve really helped me out.

  8. THANK YOUUU!

    I’ve been bashing my head against the screen for the past three hours trying to figure this out! I stumbled across our post via Google.

  9. Lucky for me I found your post right away and spent no time bashing my head against anything.
    Many many thanks.

  10. Thanks you sir. Got stuck, and found this post instantly with a google search.

    Much appreciated

  11. THANK YOU SIR.

    this post like the way to the heaven..
    i’ve ram my head to the laptop LCD for past 1 hour to solved this problem..

    you’re the man SIR..

    :)..

  12. Thanks for the tutorials it is working

  13. Thank you, this post was a great help to me and very much appreciated.

    Cheers!

  14. Thank you, thank you, thank you.

  15. Thank you!!!! I’ve been searching everywhere trying to find this answer.

  16. You’re a life saver.

  17. Thanks a lot!

  18. Oh my god, I pretty love you right now. This was driving me crazy!

  19. wow, so simple! thanks a lot! it works perfectly!

  20. Works perfectly, thank you for that!!

  21. Thanks Sir. you r the man..

  22. I am using this code, to have posts ir columns. With this code i can’t see pages with older posts. i can open page/2 but there is only the same posts i have in first page. do u know how to fix it, guys? :(

Trackbacks/Pingbacks

Leave a Reply

You will be able to edit your comment after submitting.

Follow Me on Twitter