WordPress.org

Ready to get started?Download WordPress

Forums

Excluding categories in monthly archives (2 posts)

  1. topdownjimmy
    Member
    Posted 9 years ago #

    I have a category whose posts I would like to be only accessible by browsing the category itself.

    In order to do this, I've excluded it from the home page and the archive pages using this code:

    <?php if ( is_home() OR is_date() ) {
    query_posts("cat=-12");
    } ?>

    Unfortunately, this breaks my monthly archive pages such that looking at August, for example, doesn't show JUST August, it shows all posts (it acts like the home page).

    What can I do to fix this?

    Thank you!

  2. Kafkaesqui

    Posted 9 years ago #

    Get ready for a more complicated coding bit than what you have above. This is a modification of what I use on my site:

    <?php if(is_home() || is_date()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    if($year) $archive_arg = "&year=$year";
    if($monthnum) $archive_arg .= "&monthnum=$monthnum";
    if($day) $archive_arg .= "&day=$day";
    query_posts("paged=$paged" . $archive_arg);
    } ?>

    This should not only handle archive queries correctly, but allows for pagination (next/previous posts). Note to others: this only works for a blog using custom (date) permalinks.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.