• In my (probably convoluted) way of using WP, I have a hierarchy of categories. Using “parent” categories, I display a normal “blog” but also use it for a newsletter archive and a front page (of the site…not the blog) displayer, etc. In my evolution to this usage of WP, I’ve created a situation whereby my posts per page number is getting a bit messed up. Let me explain.

    In my category hierarchy, I have “blog categories” and they are the only ones that I want to show up on my “blog page”. On my blog page I want the posts per page setting to be respected. On any other page I control it explicitly with showposts and a very specific category limit.

    So, I check which category something belongs to (its parent) before allowing it to disply, BUT that is WITHIN the Loop. So, the post_count is merrily decrementing whilst I say “no, don’t show that one, it has the wrong category parent…no not that one either”.

    What I’d like to be able to do is to INCREMENT post_count if I find that I’ve excluded a post because of its category so that in the end I display the posts per page amount of the SELECTED posts. Right now, for example, I’ve written a bunch of newsletter (non-blog) posts but few blog posts. So, while I have a posts per page count of 10, only 2 show up before it says “next page”. It counted to 10 just fine but included all those newsletter posts with it.

    Sorry to ramble, but if anyone knows a way to modify post_count in user code, that’s the bottom line question.
    Thanks for any help!

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

    (@otto42)

    ww.wp.xz.cn Admin

    Not exactly in the way you’re thinking of, no. However, it is possible.

    The problem here is the way that the posts are pulled for display in the first place. What you’re basically doing is pulling 10 posts from the database, then ignoring 8 of them. What you need to do is to change the database query such that the posts that you pull will ignore those 8 in the first place.

    I could explain to you exactly how to modify the query, but really it’s convoluted and probably unnecessary. Look at this plugin instead: Category Visibility.

    This plugin has more options than you probably need, but it will allow you to enable or disable visibility of a category from any of several different places, including the main blog page. So instead of having code in the Loop to reject specific posts, this will disable those posts from being handed to you in the Loop in the first place, for whatever specific cases you like. It will probably solve your problem as is, just disable the categories you don’t want on the “Front” page.

    If it turns out that it won’t solve your problem, then examination of the plugin will show you how to modify the post query in such a way as to limit your post selection to specific categories only. It’s tricky, but it is in there.

    On a more generic note, there’s generally a plugin out there for most things. It’s rarely necessary to resort to coding your own to change the behavior for specific cases. So when you’re looking for the plugin for your needs, try to think in broad terms, like “how do I make specific categories not show on the main page” instead of “how do I adjust the post count in the Loop”. Look for the end result instead of the way to get that result. Might help. 🙂

Viewing 1 replies (of 1 total)

The topic ‘Can post_count be modified (incremented/decremented by user code)’ is closed to new replies.