Dynamic number of posts per page
-
I have a custom field “year”, for my posts. The amount of posts that are tagged with any single year varies.
Currently in my loop I am showing 20 posts per page, in order of the tagged year. When the year changes, the year is inserted as a title, this continues for 20 posts (obviously). However the pagination does not correspond to the amount of posts for each year, so the years get broken up across pages. For example:
1932: Post Post Post Post Post Post Post Post Post
1933: Post Post Post Post Post Post Post
1934: Post Post Post Post
——Next Page——-
!934: Post Post Post Post Post Post and so on…
This is a problem because I am loading the posts in an infinite scroll manner using ajax. When the next page of 20 posts are appended to the page I usually end up with one year being broken up, and having two titles, like so:
1934: Post Post Post Post (these posts were on the current page)
1934: Post Post Post Post Post Post (these posts are on the next “page” and have been appended)
Is there any way that I can force the page count to change depending on how many posts are left for the current year, so one year never gets broken up. In a way force any “leftover” posts for that year to be included. Or perhaps there is another method to solve this problem?
Thank you
- The topic ‘Dynamic number of posts per page’ is closed to new replies.