<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bin-Blog &#187; post</title>
	<atom:link href="http://www.bin-co.com/blog/tag/post/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Show Related Post in WordPress Without a Plugin</title>
		<link>http://www.bin-co.com/blog/2009/04/show-related-post-in-wordpress-without-a-plugin/</link>
		<comments>http://www.bin-co.com/blog/2009/04/show-related-post-in-wordpress-without-a-plugin/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 18:00:29 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin-killer]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[related]]></category>
		<category><![CDATA[series]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=256</guid>
		<description><![CDATA[Related posts is a very popular feature. My default wordpress installation often includes a plugin that has this functionality. There are quite a few plugins that lets you have this feature.]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2009/03/wordpress-150x150.jpg" alt="WordPress Metal Logo" title="WordPress Metal Logo" width="150" height="150" class="alignnone size-full wp-image-239 intro" align="right" /></p>
<p class="intro">Related posts is a very popular feature. My default wordpress installation often includes a plugin that has this functionality. There are quite a few plugins that lets you have this feature&#8230;</p>
<ul>
<li><a href="http://mitcho.com/code/yarpp/">Yet Another Related Posts Plugin (YARPP)</a></li>
<li><a href="http://rmarsh.com/plugins/similar-posts/">Similar Posts</a></li>
<li><a href="http://blendworx.com/aizattos-related-posts-wordpress-plugin/">Aizattos Related Posts</a></li>
<li><a href="http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/">WordPress Related Posts</a></li>
<li><a href="http://wasabi.pbwiki.com/Related%20Entries">Wasabi Related entries</a></li>
</ul>
<h2>The Code</h2>
<p>WordPress has been supporting tags in its new released &#8211; so the related posts feature can be implemented without the help of any plugins. All we have to do is find the <strong>other posts with some same tags as the current post</strong>. Just open the <strong><code>single.php</code> file in your theme and add this bit of code</strong> where you want the related posts to show up&#8230;</p>
<pre><code class="php">&lt;?php
$tags = wp_get_post_tags($post-&gt;ID);
if ($tags) {
	$tag_ids = array();
	foreach($tags as $individual_tag) $tag_ids[] = $individual_tag-&gt;term_id;

	$args=array(
		'tag__in' =&gt; $tag_ids,
		'post__not_in' =&gt; array($post-&gt;ID),
		'showposts'=&gt;5, // Number of related posts that will be shown.
		'caller_get_posts'=&gt;1
	);
	$my_query = new wp_query($args);
	if( $my_query-&gt;have_posts() ) {
		echo '&lt;h3&gt;Related Posts&lt;/h3&gt;&lt;ul&gt;';
		while ($my_query-&gt;have_posts()) {
			$my_query-&gt;the_post();
		?&gt;
			&lt;li&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;
		&lt;?php
		}
		echo '&lt;/ul&gt;';
	}
}
?&gt;</code></pre>
<p>This code finds the other post with any one of the tag that the current post has. If you want to show the <strong>posts with any one of the categories</strong> that the current post has, use this code instead&#8230;</p>
<pre><code class="php">&lt;?php
$categories = get_the_category($post-&gt;ID);
if ($categories) {
	$category_ids = array();
	foreach($categories as $individual_category) $category_ids[] = $individual_category-&gt;term_id;

	$args=array(
		'category__in' =&gt; $category_ids,
		'post__not_in' =&gt; array($post-&gt;ID),
		'showposts'=&gt;5, // Number of related posts that will be shown.
		'caller_get_posts'=&gt;1
	);
	// Rest is the same as the previous code
</code></pre>
<h2>WordPress Plugin Killer Series</h2>
<p>For those who came in late, this post is part of the <a href="http://www.bin-co.com/blog/2009/03/wordpress-plugin-killer-series/">WordPress Plugin Killer Series</a>. This series will show you how to duplicate the functionality of the a few wordpress plugins without having to install it using custom code in the wordpress theme. The previous posts in this series are&#8230;</p>
<ul>
<li><a href="http://www.bin-co.com/blog/2009/02/avoid-duplicate-content-use-canonical-url-in-wordpress-fix-plugin/">Avoid Duplicate Content &#8211; Use Canonical URL in WordPress</a></li>
<li><a href="http://www.bin-co.com/blog/2009/03/show-popular-posts-in-wordpress-without-a-plugin/">Show Popular Posts in WordPress &#8211; without a plugin</a></li>
<li><a href="http://www.bin-co.com/blog/2009/03/adding-social-bookmarking-button-in-wordpress-without-plugins/">Adding Social Bookmarking Button in WordPress &#8211; Without Plugins</a></li>
</ul>
<h3>More Resources</h3>
<ul>
<li><a href="http://www.smashingmagazine.com/2009/04/15/10-exceptional-wordpress-hacks/">10 Exceptional WordPress Hacks</a></li>
<li><a href="http://www.wprecipes.com/how-to-show-related-posts-without-a-plugin">How to: Show related posts without a plugin</a></li>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2009/04/show-related-post-in-wordpress-without-a-plugin/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
	</channel>
</rss>

