Support » Plugins » Using query_posts with monthly archives

  • Resolved Tyssen


    I want to exclude a certain category from my monthly archives, so that if in a particular month, the only posts are from the excluded category, the link to the month doesn’t show up at all.
    I’m working with query_posts to filter out the category, but not sure where I go from there to display the correct monthly links instead of links to the individual posts?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Anyone?

    You say you want to “exclude a certain category from my monthly archives” so when one is in a month the only posts are “from the excluded category.” Sorry but that doesn’t make much sense to me.

    Try again to explain in plain language what you want to do here, and in as much detail as you can provide.

    Category A – included
    Category B – excluded

    January – 1 post Cat A, 1 post Cat B, therefore January shows up as a link in the monthly archive because of the Cat A post.

    February – 1 post Cat B – the only post is from the category to be excluded so the link to February isn’t shown.

    Ah, so you’re just asking for links to (as in the sidebar) the archives? I think I can help on that.

    As you can see by the code this does not use query_posts(), but rather a simple (well…) query to the database. One can certainly create a list of all posts excluding those from your specific category using query_posts(), but there’d be a large overhead doing that just to generate a monthly archive link list out of it.

    Thanks for that. I guess when I asked I wondered if there was some particular WP way of doing it by combining one of their in-built functions, but building your own SQL query works just as well, so I’ll go with that 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Using query_posts with monthly archives’ is closed to new replies.