Feature
Post

Category
Code


WordPress Snippet: More Posts in the Same Category

From an SEO perspective there’s no point in displaying the exact same content in every single sidebar on your WordPress site. A great piece of snippet offers a great solution on a very dynamic single post sidebar. Just to be clear, this snippet only works if you use just use one category per post for your posts.

<?php global $post; 
	$categories = get_the_category();
	foreach ($categories as $category) :? >
	<h4>More posts from this category</h4>
		<ul>
		<?php $posts = get_posts('numberposts=7&category='. $category->term_id);
		foreach($posts as $post) : ?>
			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
		<?php endforeach; ?>
			<li><strong><a href="<?php echo get_category_link($category->term_id);?>" title="See all posts in the category <?php echo $category->name; ?>">Archive for '<?php echo $category->name; ?>' Category &raquo;</a></strong></li>
	<?php endforeach; ?>
		</ul>

As you can see this snippet does two things. First, it displays the seven latest posts of the category used for the post you’re currently reading. Secondly, it shows a link to the category archive used. A great way to get your readers to stay longer on your blog. While you’re at it, consider styling those category views using WordPress category templates.

You need these two too

If your theme currently doesn’t have a separate single post sidebar you should have a look at the Widget Logic plugin. It allows you to specify which widget should be displayed on which view. Also, you will need plugin that will allow you to use php inside a widget like Exec PHP.

theappreviewer.com