Depending on the way you are using WordPress this may, or may not, work well for you. It kind of relies on the fact that posts will be related because they are in the same category. If for whatever reason posts can be unrelated to each other, although they are in the same category, you’ll probably want to use a plugin like YARPP.

The Idea!

We want to show the related posts at the bottom of the post on single.php (kinda like I do), but use no plugins. To do this we are going to ask WordPress what category the current post is in, and then use it to make a custom loop. Got it? Good, let’s go.

The Code!

First we need to ask WordPress what category the current post is in.

$category = get_the_category($post->ID);

This will give us back an array, with one entry per category, containing an object with that category’s information within it. We also need to know which post we are looking at so we can exclude it from our results.

$current_post = $post->ID;

Now let’s add that together with a call to get_posts().

$category = get_the_category($post->ID);
$current_post = $post->ID;
$posts = get_posts('numberposts=3&category=' . $category[0]->cat_ID . '&exclude=' . $current_post);
?>
<ul>
<?php
foreach($posts as $post) {
?>
    <li><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
<?php
}
?>
</ul>

There we have it. In get_posts(); we have asked for 3 posts, from the current category, and excluding the current post. $category is an array with an object inside hence the need for the [0] on the variable.

The Limitations!

Well as I said before one major limitation is that it will never be as good as a related plugin like YARPP due to the special scoring system it uses. However it is great for certain websites/blogs. You may also notice that it only gets posts from the first category attached to the post, you can do something about that should you want to.

$category = get_the_category($post->ID);
$current_post = $post->ID;
if(isset($category[1])) {
    foreach($category as $c) {
        $categories = $c->cat_ID.',';
    }
} else {
    $categories = $category[0]->cat_ID;
}
$posts = get_posts('numberposts=3&category=' . $categories . '&exclude=' . $current_post);
//Rest of code from before...

That will create a comma separated list of the category IDs which is how get_posts() expects it. It will however only do it should it detect that the category array has more than one entry saving a bit of time & memory.

Sadly I can't provide an example for this one. However as always if you have any questions, or suggestions please let me know using the comments.