Support » Themes and Templates » How to get variable post limit (pagination not working properly)

  • Hello!

    I have a website where I use the so called “The Loop”. I use a single counter-based Loop in my index page, just like this code.

    However, I added something a new conditional query inside that Loop, that renders an extra post (or maybe more) only if it is related to one of those in the principal Loop (I do that with custom fields).

    So this is what my page looks like:

    I have a post on the left side, and the next five on the right side. If one of this posts has a custom field (let’s call it “related-news”) set to an ID, than that posts set in the custom field is also shown.

    So let’s say I have 6 articles on the main page, and of them all, the article number 3 has a custom field set to a related article. Then I will have:

    On the left: Article no. 1
    On the right: Article no. 2, Article no. 3, Related Article of no. 3, Article no.4, Article no. 5.

    A total of 7 articles. OK, now I must set the maximum number of articles to be shown on a page (otherwise, the Loop will show me all articles on the main page). Let’s set it to 7. All looks perfect. On the second page also:

    On the left: Article no. 7.
    On the right: Article no. 8, Article no. 9, Article no. 10, Article no. 11, Article no. 12.

    A total of 6 articles. Now because I’ve setup the number of posts per page to 7, if I hit the third page, the pagination skips a post: the third page begins with Article no. 14, not Article no. 13 like it should be.

    Is there a way to make the post limit variable, so that it changes depending on the number of posts generated by the “The Loop” on each page?

Viewing 1 replies (of 1 total)
  • My guess is that the condition query you’ve inserted is somehow blowing out the pagination, but without seeing the code its hard to say. Paste your code to the pastebin and maybe someone will see the problem.

Viewing 1 replies (of 1 total)
  • The topic ‘How to get variable post limit (pagination not working properly)’ is closed to new replies.