WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using query_posts with monthly archives (6 posts)

  1. Tyssen
    Member
    Posted 8 years ago #

    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?

  2. Tyssen
    Member
    Posted 8 years ago #

    Anyone?

  3. Kafkaesqui

    Posted 8 years ago #

    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.

  4. Tyssen
    Member
    Posted 8 years ago #

    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.

  5. Kafkaesqui

    Posted 8 years ago #

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

    http://pastebin.co.uk/587

    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.

  6. Tyssen
    Member
    Posted 8 years ago #

    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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic