I want to add some related articles at the bottom of my wordpress posts.
All my posts are categorized in BOTH a parent and child category. I need to pull four RANDOM related posts from the same CHILD category as the main post (not the first four in the category) then display them at the bottom of the post, through single.php
.
I'm a newbie to WP & the loop.... any ideas on how I do this?
Edited to include the code I'm using to display posts on category pages - the random related posts need to be in this same grid.
<!-- START OF THE FLEX CONTAINER, THE UNORDERED LIST -->
<ul class="grid-wrap">
<!-- WP LOOP STARTS HERE -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- LIST ITEM FOR EACH POST -->
<li class="grid-item">
<!-- FEATURED IMAGE FOR THE POST -->
<p>
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( 'small' ); ?></a>
<?php endif; ?>
</p>
<!-- POST TITLE -->
<h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endwhile; ?>
<?php endif; ?>
<!-- END OF THE LIST ITEM -->
</li>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>></div>
<!-- END OF THE FLEX CONTAINER -->
</ul>