Get Posts Related To Category

wordpress-tricks

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:

Source code    
$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 ++;
    }
}
Kirk is a software / web developer & business consultant. He has been doing online marketing and product development for the last eight years, and been an entrepreneur for the last five. BlogWebDesigner was created to help Internet Marketers sell more stuff online.
Posted in Web DesignTagged ,