WordPress: Show Posts In The Same Category

A good way to keep visitors on your site and reading more posts, is to add a “related posts” section on the end of a post that displays posts within the same category.

This can be achieved very simply by adding the following code to your single.php template file:

<div class="related">
<h6>Related Posts from <!--?php the_category(', '); ?--></h6>
<ul>
<ul><!--?php <br ?--> foreach(get_the_category() as $category) { $cat = $category-&gt;cat_ID; }</ul>
</ul>
<ul>
<ul>query_posts('showposts=4' . 'orderby=rand&amp;cat=' . $cat );</ul>
</ul>
<ul>
<ul>while (have_posts()) : the_post();</ul>
</ul>
<ul>
<ul>ob_start(); the_title(); $title = ob_get_clean();</ul>
</ul>
<ul>
<ul>if ($title != $post_title){</ul>
</ul>
<ul>
<ul>?&gt;
	<li></li>
</ul>
</ul>
&nbsp;

</div>
Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Google Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358