pmcasey
Member
Posted 3 years ago #
I am creating new pages for one of my blogs, http://knoxify.com/ and I would like to display a list in the sidebar of the 5 latest posts with a certain tag.
I have read various tutorials similar to this topic with no luck. Does anyone know how to accomplish this?
Thanks in advance for the help.
Dunkkan
Member
Posted 3 years ago #
This will take 5 posts, randomly, having the specified tag associated whit them.
I hope I don't forget anything. It should work in the sidebar.
In case of problems, add <?php rewind_posts(); ?> just after calling the header in the template.
<ul>
<?php
$rand_posts = get_posts('numberposts=5&tag=WHATEVER&orderby=rand');
foreach( $rand_posts as $post ) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
</ul>