I figured out how to exclude the current post from displaying in my single-post view sidebar, but now I want to exclude parent categories and display only children. Any ideas how to do this? Much obliged!!
<div id="sidebar" class="grid_4">
<div class="item portfolio"><hr></hr>
<h4>Similar Items</h4>
<?php
if ( is_single() ) {
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$first_cat = $cats[0];
$args=array(
'cat' => $first_cat, //cat__not_in wouldn't work
'post__not_in' => array($post->ID),
'showposts'=>8,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php if (in_category('15')) continue; ?>
<div ID="similarentry"><ul>
<li ID="similarthmb"><?php get_the_image( array( 'custom_key' => array( 'thumbnail' ), 'default_size' => 'thumbnail', 'width' => '119', 'height' => '75', 'link_to_post' => true ) ); ?></li>
<li ID="similarttl"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title() ?></a></li>
</ul></div>
<?php
endwhile;
} //if ($my_query)
} //if ($cats)
wp_reset_query(); // Restore global post data stomped by the_post().
} //if (is_single())
?>
</div></div>
I spent almost two months building and debugging Total Widget Control to do exactly this for all of a sites widgets. Bear with me as I strip the code out of Total Widget Control and try to make it usable for you.
Comments inline:
Editors note:
INSERT_YOUR_CATEGORY_PARENT_HERE
has to be replaced, else it would be seen as undefined constant and throws an Error.