Hopefully, the title was clear enough 8-)
In the sidebar, I am using get_archives to display the last 10 posts. I'd like to be able to exclude a given category from this list. Is that possible?
Hopefully, the title was clear enough 8-)
In the sidebar, I am using get_archives to display the last 10 posts. I'd like to be able to exclude a given category from this list. Is that possible?
As you can see here Template_Tags/get_archives there is no such parameter to exclude categories. You may want to try to use a "recent posts" plugin.
Ah, well.
Thanks, anyway, Moshu. I had seen that. I wasn't sure if there was another template tag that returned the same information with more -- customization.
While I am adding a few plugins, I'm trying to run as lean as possible...
I use the following code to generate a list of the titles of the 10 most recent post in my sidebar and exclude 1 category (with id=18 in this example):
<ul>
<?php $temp_query = $wp_query; query_posts('showposts=10&cat=-18'); ?>
<?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>
You can exclude only 1 category, in this example category 18 is excluded (note the minus sign).
There is one disadvantage: only post that have ONLY category 18 assigned, are excluded. If a post has other categories besides category 18 assigned, it will not be excluded.
Normally you would use
<?php wp_get_archives('type=postbypost&limit=10'); ?>
to generate such a list, but wp_get_archives doesn't have an exlude parameter.
I am using the Asides in my sidebar and don't want to show my Aside posts to show in the Recent posts, so my Asides all have a category with id=18 in the above example.
See the documentation on the query_posts template tag for more options.
oh i was trying to work on something like this! thanks so much! ^_^
This topic has been closed to new replies.