pulling recent posts from a random category or none if category is empty
-
In my sidebar I am using this code to display 8 recent posts from whatever category is being viewed: `<?php $post_cats=wp_get_post_categories($post->ID);?>
<?php
$args=array(
‘showposts’=>8,
‘cat’=>$post_cats[0]
);
$postslist = get_posts($args);
if ($postslist) {
foreach ($postslist as $mypost) :
?>- ID); ?>”><?php echo $mypost->post_title; ?>
<?php endforeach;
}
}
?>`When the category is empty, There should be nothing displayed – instead, I am getting posts from a different category. There must be an easy way to fix this…
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘pulling recent posts from a random category or none if category is empty’ is closed to new replies.