I am displaying related posts with the below code:
<div class="my-related-posts"><h4>You may also be interested in...</h4><ul
class="relatedposts">
<?php
$posts = get_posts('numberposts=4&orderby=rand&category='. $category->term_id
. '&exclude=' . $current_post);
foreach($posts as $post) :
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ));
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><img
src="<?php echo esc_url( $image[0] ); ?>" alt="View more info" /></a></li>
<?php endforeach; ?><?php endforeach; ?>
</ul>
</div>
...but I want to make sure it displays posts even if no others in the same catagory...so something like
if (less than 4 related posts) {
display any other posts from other catagories
}
Thanks for your help.
setup_postdata($post)
andwp_reset_postdata()
with your 'foreach' loop - codex.wordpress.org/Template_Tags/get_posts#Examples