Friday, July 2, 2010

show me more than the post really in the current category

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'=>5,
'caller_get_posts'=>1 ); $my_query = new WP_Query($args);
if( $my_query->have_posts() ) { echo 'Related Posts';
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></p>
<?php endwhile; } //if ($my_query) } //if ($cats)
wp_reset_query(); // Restore global post data stomped by the_post().
} //if (is_single())
?>


More--->
http://wordpress.org/support/topic/310930

No comments:

Post a Comment