• I couldn’t find an answer to this on wp.org so i thought i would post it up because it might come in useful to someone else later.

    If you want to make a list of “stuff” with wp_get_archives, you will realize that you cannot pick what categories that are used.(stuff, being whatever the function can do. Check here.)

    I used it for a “recent posts” section on my site. The bad part was that it was including some categories i didn’t want in the list. So i replaced this:

    <ul>
    <?php wp_get_archives('type=postbypost&limit=10'); ?>
    </ul>

    With this:

    <ul>
    <?php $temp_query = $wp_query; query_posts("showposts=10&cat=-1000"); ?>
    <?php while (have_posts()) { the_post(); ?>
    <li><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to &ldquo;<?php the_title(); ?>&rdquo;"><?php the_title(); ?></a></li>
    <?php } $wp_query = $temp_query; ?>
    </ul>

    Be sure to replace the 1000 with the category ID that you want to exclude(make sure to leave the negative sign).

    Another bit of information about this, is that it will also exclude all the children categories to whatever category you choose to exclude.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thanks so much

    Thanks from me also, saved me so much time!

    NOTE* if you just want to include one category, get rid of the minus sign before the 1000 and replace 1000 with the number of the cat you want to use ??

    would it be possible to show monthly archives with this method?

    <ul>
    <?php wp_get_archives('type=monthly&limit=7');?>
    </ul>

    FYI, this also works:

    <ul>
    <?php
    $recent = new WP_Query();
    $recent->query(array('category__and' => array(1000), 'showposts'=>10));
    while($recent -> have_posts()) : $recent -> the_post(); ?>
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    </ul>

    Brilliant, it works perfectly. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to: exclude categories wp_get_archives’ is closed to new replies.