Support » Fixing WordPress » controlling loop post count

  • On my blog, I have a series of conditionals. Each conditional has a slightly different output as each is for different categories of posts.

    One thing that I have noticed is that if a category isn’t displayed because of my conditionals in the loop, wordpress still counts it as being diplayed, and sometimes only shows 7 posts (when there should be 10).

    Is there a way to control the number of posts that wordpress *thinks* it has displayed?

    (what I am aiming to do is lower the post count by one to account for the post not shown)

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    No. It doesn’t work that way.

    Basically, you’re going to the database and telling it to give you the most recent 10 posts. This happens before the Loop ever starts. If you don’t display some of those posts, then you don’t have any easy way to tell WordPress to go fetch more of them.

    If you want to exclude categories entirely from your Loop without affecting the count, then you have to do it in the initial query. The Category Visibility plugin does this sort of thing:

    Ok. The site says that plugin does not work in 2.1

    Is there any other way to compensate for this problem, but still be able to use the loop for those categories when needed?

    Go back to that link and read closer. Isn’t there a 2.1 beta version listed?

    Or, have a look at Ultimate Category Excluder plugin

    I’d like to know how to do this without a plugin. The Loop entry in the codex says the following about excluding categories in The Loop:

    Please note that even though the post is not being displayed it is still being counted by WordPress as having been shown — this means that if you have WordPress set to show at most seven posts and that two of the last seven are from Category 3 then you will only display five posts on your main page. If this is a problem for you, there is more complicated hack you can employ described in the Layout and Design FAQ or you can use query_posts if you only need to exclude one category from the loop.

    However, the Layout and Design FAQ doesn’t seem to mention this complicated hack. Would anyone know what it involves?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘controlling loop post count’ is closed to new replies.