<?php
$cat=get_cat_ID('yourcategoryname');
$args=array(
'category__not_in' => array($cat),
'showposts'=>-1,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><small><?php the_time('m.d.y') ?></small> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
?>
Awesomely fast response Michael! Now I know why you are the moderator. Thanks.
Just one more thing, I want the exclusion category to be dynamically scripted to match the lowercase of the blog title with “-” replacing the spaces. So if the Blog title is “My Blue Widget”, I want the exclusion category to be “my-blue-widget”…
Also, I’m using a list item structure, but no biggie…here’s my code…Would you do anything differently?
<div class="xmenu side"><span>Recent Posts</span>
<ul>
<?php
$mycat = strtolower(get_bloginfo());
$mycat2 = str_replace (" ", "-", $mycat);
$cat=get_cat_ID($mycat2);
$args=array('category__not_in' => array($cat),'showposts'=>-1,'caller_get_posts'=>1);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
}
?>
</ul>
</div>
Michael, thanks again for your help. I’ve streamlined the code a bit but for some reason, I’m getting a single post listed that is in the exclude category…
(the exclude category is named “top-menu” and the slug is also named top-menu, which is being referenced with get_cat_ID?)
<ul><h3>Recent Posts(not in the top-menu category</h3>
<?php
global $post;
$cat=get_cat_ID('top-menu');
$myposts2 = get_posts('category!='.$cat);
foreach($myposts2 as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
I’ve got $cat and $post declared in the header as well, will these conflict with one another? Particularly since $post is global in scope?
I’m pretty sure this won’t work
$myposts2 = get_posts('category!='.$cat);
See other arguments here:
query_posts()
ALMOST THERE!!! I got it all sorted out, but now I need to exclude all sticky posts…
<ul><h3>Recent Posts</h3>
<?php
global $post;
$cat=get_cat_ID('top-menu');
$myposts2 = get_posts('cat='.-$cat);
foreach($myposts2 as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>
This did it….
<ul><h3>Recent Posts</h3>
<?php
global $post;
$cat=get_cat_ID('top-menu');
$myposts2=get_posts(array('post__not_in'=>get_option('sticky_posts'),'cat'=>-$cat));
foreach($myposts2 as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>