-2

I used query_posts('offset=3') in index.php, while there exist a problem in pagination. In all page it show the same content of first page.

How to solve this problem?

  • 1
    Do not use query_posts, period. There is a huge amount of resources on site about WHY not to use query_posts. Also, there is resources on-site about offset and pagination. I know I have done a post on this not long ago – Pieter Goosen Apr 13 '16 at 9:22
0

In order to remove the duplicate posts, I used the below process in one of the theme I worked on.

  1. Create a global variable
  2. Store the post ID of first loop on the variable
  3. On next loop, use post__not_in to remove the already shown posts.

Or, you can also check if current post id is in array of global variable and skip that post.

  • offset breaks the internal pagination functionality of WP_Query, all you must do is do manually recalculate that. Creating a global is definitely a very very bad idea which by itself deserves a downvote – Pieter Goosen Apr 13 '16 at 10:43
  • Thanks for providing reason instead of just down-voting and moving away. Despite knowing using global variable is bad idea, I had to go through this method as I couldn't find any other way to do so. Using the method I mentioned doesn't break the pagination btw. If possible, can you please help me with what this question asked? I would love to know the better way. Thanks! @PieterGoosen – Rajeeb Apr 13 '16 at 10:54
  • 1
    I have recently done a post on this, check it out here. – Pieter Goosen Apr 13 '16 at 10:59
  • Good one. Maybe I was just thinking in one direction. I used the process mentioned in answer to remove duplicate posts where the posts were being fetched by widgets for magazine page. Do you think your version of answer can be extended to support that magazine layout I just mentioned? @PieterGoosen – Rajeeb Apr 13 '16 at 11:20
  • If you need to remove duplicates from widgets, or any secondary query, then your method will work. My method in the link is meant for the main query, which is the desired method to OP's problem – Pieter Goosen Apr 13 '16 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.