
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.




August 29th, 2009 at 5:52 pm
Thanks for the solution! I’ve been struggling to get pagination to work on my new site and now it’s fixed!
Cheers mate
September 18th, 2009 at 7:13 pm
Thanks! Worked for me to solve WordPress Next/Previous Page Links Problem (query_post Pagination Problem)
October 5th, 2009 at 7:59 am
Awesome solution for page links problem – thanks so much!
February 28th, 2010 at 11:20 am
You’re a life saver! I spent so much time trying to fix this, and then your post appeared!
THANK YOU
April 1st, 2010 at 4:06 pm
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!
April 22nd, 2010 at 9:23 pm
Brilliant.
Thanks for this great tip, helped me sort this out in 2 mins
April 28th, 2010 at 8:30 pm
Thanks for this – I was very stuck and you’ve really helped me out.
April 30th, 2010 at 9:06 pm
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.
May 4th, 2010 at 11:13 pm
Lucky for me I found your post right away and spent no time bashing my head against anything.
Many many thanks.
July 20th, 2010 at 4:00 am
Thanks you sir. Got stuck, and found this post instantly with a google search.
Much appreciated
August 5th, 2010 at 2:52 pm
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..
October 4th, 2010 at 4:29 pm
Thanks for the tutorials it is working
October 13th, 2010 at 6:17 am
Thank you, this post was a great help to me and very much appreciated.
Cheers!
October 18th, 2010 at 9:14 am
Thank you, thank you, thank you.
November 6th, 2010 at 11:54 pm
Thank you!!!! I’ve been searching everywhere trying to find this answer.
December 4th, 2010 at 11:35 pm
You’re a life saver.
December 13th, 2010 at 9:09 am
Thanks a lot!
December 29th, 2010 at 3:23 am
Oh my god, I pretty love you right now. This was driving me crazy!
February 16th, 2011 at 6:39 pm
wow, so simple! thanks a lot! it works perfectly!
July 24th, 2011 at 2:08 pm
Works perfectly, thank you for that!!
September 22nd, 2011 at 4:54 pm
Thanks Sir. you r the man..
January 19th, 2012 at 3:57 pm
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?