Related Posts in WordPress Controlled With Categories

Related posts are a sure way to present your blog articles to the reader of a specific taste who is reading one post only. Now it depends upon you that where you actually want to show the related posts, one good practise is to show the related post at the end of a specific post since it will give the reader opportunity to navigate to the other articles of the website with quite an ease once he ends up reading that article. Related posts can be controlled with the tags also but this time I am going to show that how can you show up related posts with the help of categories.

Related Posts in WordPress VIA categories:

Suppose reader is going to read a post under the category of the Android and then he wants to read more posts also from the same category then here related posts role come into play. If you add related posts at the end of that specific post then he will be able to navigate to the other posts of the site under the category Android.

Adding Related Posts in WordPress – The Code Part:

The code is divided into the two parts, one is the style for the related posts and the other is the php code for calling the related posts. First I’ll show you how to add the php code to the post page of your blog and later the I’ll tell you how to add the style code to style the related posts, the style is damn unique as I know the line between creativity and over designing :P.

Locating the Post/Article Template in your Blog:

First you need to locate the article template of your blog, since we need to add the related posts under the post page of your blog. Just after the user has completed reading the post. Follow the steps below:

Login to your wordpress and go to Appearance>Editor. There you need to locate single.php. Click single.php and then add the following code below “<?php the_content(); ?>”

Adding Related posts PHP Code in single.php:

Open up the single.php and then add the below code at the end of your post content i-e after the <?php the_content(); ?>. Don’t forget to update the file after adding the below code i-e press “Update File”

Adding the Style Code for Related Posts in Style.css:

Now, you need to add the related post style code (CSS Code) to the style.css of your wordpress theme. Now again you need to open up the editor in the appearance tab of your wordpress blog and then go to style.css (By Default the editor opens up style.css) Copy the below code and then paste it into the style.css, you can paste it anywhere but if you are a noob or a new person then you need to copy it and add it at the end of the style.css

After pasting then update the code by saving the file through the button provided below “Update File“. Now go to the article page and then scroll to the end of the page, there you will be able to see the related posts. if you have any questions then you can ask below through the comments.