How to: exclude categories wp_get_archives
-
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 “<?php the_title(); ?>”"><?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.
- The topic ‘How to: exclude categories wp_get_archives’ is closed to new replies.