How to Display Related Posts in Thesis Theme without a Plugin

This tutorial is exclusively for Thesis Framework, a new templating system for WordPress. Create any sort of layout for your website using Drag & Drop Builder.

Share This Article:

How to Display Related Posts in Thesis Theme without a Plugin. Its always recommended to display related posts in your blog, it not only improves user experience, but also helps to boost search engine rankings.

display-related-posts-thesis-theme

After reading complete post, its necessary to include something related to that article. In many WordPress themes, links to next and previously published posts will be displayed, which is also a good option.

If you are using Genesis Theme, here is an article for you: Display related posts

Why to Display Related Posts without Using a Plugin ?

We specifically mention “Without a Plugin” context in the title and there is a special reason behind it. It is not always good to use too many plugins on any blog, they surely will affect the loading speed. So, we always like to use a piece of handy code for small functionality and recommend the same for our readers.

Now, coming to related posts in thesis, they can be displayed based on categories and tags. But using categories is the best method and here are some specific reasons for that.

Learn: How to customize 404 Error Page in Thesis Theme

Why to display Category Based Related Posts ?

  • In most of the blogs tags are not used at all, but categories will be assigned.
  • Compared to tags, more relevant results will be displayed for any category.
  • The code used will be light and can be implemented easily.

These are some simple reasons which can be considered to some extent.

Read: Thesis 1.8.5 Now Available for Download

Display Related Posts in Thesis Theme without a Plugin

Follow these steps to add related posts to single post page.

  • Login to WordPress dashboard and go to Appearance Menu.
  • Open “custom_functions.php” file, add below code to it and Update the file .
  • Now, open any post in your blog to check if code is working on it.
function custom_related_posts() {
if (is_single()) {
global $post;
$current_post = $post->ID;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<div class="related-posts">
<h4>Related Articles...</h4>
<ul>
<?php
$posts = get_posts('numberposts=8&category='. $category->term_id . '&exclude=' . $current_post);
foreach($posts as $post) :
?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?><?php endforeach; ?>
</ul>
</div>
<?php
}
wp_reset_query();
}
add_action('thesis_hook_after_post','custom_related_posts');

Functionality of this Code

  • Conditional tag is_single() is used and hence related posts are displayed in single post page only.
  • By default, 8 posts are displayed and change the number to any positive number based on the requirement.
  • Also, you can modify the heading of related posts by using a custom text.

Styling Related Posts in Thesis Theme using CSS

Now, final part is to style these related posts using CSS. Add the below code to custom.css file and update it.

.custom .related-posts { margin:10px 0; }
.custom .related-posts h4 {font-size: 18px;line-height: 36px;font-weight:bold;}
.custom .related-posts ul {list-style: square outside none;}
.custom .related-posts ul li {padding:5px 10px;}
.custom .related-posts li a { text-decoration:none; }
.custom .related-posts li a:hover { color:#333; }

Finally, you have successfully added “Related Posts to Thesis Theme”. If you have any query regarding this article, drop a comment and we are always glad to help you.

This tutorial is exclusively for Thesis Framework, a new templating system for WordPress. Create any sort of layout for your website using Drag & Drop Builder.

Genesis is the most flexible WordPress theme framework that comes with tons of options. We have been using Genesis on all of our blogs and recommending the same to you. Every bit of it is coded according to the standards. Give it a try!

Comments

  1. Istiak Rayhan says:

    I tried to use this in my blog. After putting the code in my custom_functions.php file I reloaded my blog. Sidebar widgets got messed up. Any suggestions?

  2. Electrical engineering says:

    Using plugin not so good cause it slows down loading page so using code is the best way to for showing related post plugin.

Speak Your MindComments Policy →

*

Looking for More Awesomeness?

Read previous post:
custom-404-error-page-genesis
How to Create Custom 404 Page in Genesis Theme

How to Create Custom 404 Page in Genesis Theme. Here is the custom code that helps to create a custom...

Close