Get Posts Related To Category

Written by
Categories: WordPress
No Comments »
Get Posts Related To Category


Today, in this method to displaying related posts based on category, surely to help visitors staying longer on your blog.

Before start changes in any file, I will firstly recommend you to back up your file before start doing anything to your Single.php file, or else you’ll be sorry if anything goes wrong, ok let’s get started.

Login to your WordPress dashboard , go to your Appearance-> Editor and open your Single.php file, and add this code beneath your post content:

Paste below code:

[php]
$posts = get_posts(‘numberposts=6&offset=0&orderby=post_date&order=DESC&category=’.$category);
$count = 0;
foreach ($posts as $post) {
if ( $post->ID == $this_post->ID || $count == 5) {
unset($posts[$count]);
} else {
$count ++;
}
}
[/php]

Tags:

About the Author: Kirk Maxi
http://www.blogwebdesigner.com
A software / web developer and serial entrepreneur, Kirk has been developing and coding since the beginning of the internet and is currently based in Sydney Australia. In his spare time, he runs a number of Web projects and also updates BlogWebDesigner.com with anything that he finds interesting in the Web Design genre.

Leave a reply