Showing related post below every article is one of the best way to control the bounce rate of your website, as users get more content on related topics. You can you use some great plugins like WordPress Related Posts, Yet Another Related Posts Plugin, Relevant to solve this purpose. But it’s always better to use less number of plugins to keep website fast loading. If you are a Genesis framework user you can easily show related posts below every post by adding some php code in child theme’s functions.php file. But before any experiments please backup your blog. If something goes wrong your blog will not load.
You can use the inbuilt editor of WordPress to add the code, but it’s better to download functions.php from child theme folder inside /wp-content/theme folder of WordPress. There are two options for related posts, you can show them according to categories or tags attached with post, with a bit of coding knowledge you can create related post function with both tags that will be more precise.
Update: Show Related Posts with Thumbnails in Genesis without any Plugin
Related post based on category:
Code for tag based related post display is nearly about same. Just replace all “cat” with “tag” and “categories” with “tags”. To change number of related posts shown change the number in [ ‘showposts‘ => 4, ] line , to ignore sticky posts to appear in related section just change the number “0” to “1” in [‘ignore_sticky_posts‘ => 0,] line.
Those using old version of Genesis framework or child themes will face problem with this code as they have recently added HTML5 Markup on all the themes. To solve it just replace ‘genesis_after_entry_content‘ with ‘genesis_after_post_content‘.
Thats all for now will be back with some new Genesis tutorials soon. Have any query ? Just comment below.
Great, I finding this one. So can you explain more detail? I don’t know where to add this code?
Are you using Genesis child themes? Then you have to add the mentioned code in the end of functions.php file.
I am so happy you posted this. I need this because my hosting provider does not allow the popular related post plugins. I currently use special post plugin from codecanyon that is awesome. They also cache the query so it’s not hitting the database every time. I believe it does a refresh every 24 hours.
Could you update the code to do that?
I’ll keep that in mind & the feature will be included next time I update the code. Thanks for the suggestion.
-Arup
Thanks Arup. My blog looks cool with this Related Post widget. 🙂
Great to know that 😀 . To suggest any improvement or issue with the code ping me.
Hi,
Thanks for sharing this valuable post, Much appreciated. Keep posting such articles.
Thanks for your feedback.
Please does the plugin comes with thumbnails?
Look as I mentioned in post title, it’s no plugin. To show thumbnail using the code, you have to fetch the featured images on the post and add that to $related.
Thanks brother, You are too good.
You are welcome, my friend.
Thanks, I made related post in my blog.
Great to know that.
its a great pleasure to be here.
You are welcome bro. One suggestion for you don’t post comments with links that are not necessary.
am so happy you posted this. I need this because my hosting provider does not allow the popular related post plugins. I currently use special post plugin from codecanyon that is awesome. They also cache the query so it’s not hitting the database every time. I believe it does a refresh every 24 hours.
Could you update the code to do that?
I can’t assure you, but surely will try to code that.
Nice tutorial. Explained easily.
It would be good if this feature was built in because some people do not like coding at all.
Thanks Arup.
Yes, I think Studiopress will do that in near future.
Arup this is awesome! thank you so much for sharing.
Can you explaim me again how to add thumbnails?
thank you so much!
Thanks mate for sharing this. It works well 🙂
Glad to know 😀
I’m inspired by your post. As a freelance writer, every post is vital & yours is no exception.
That’s what i was looking for. Installing a number of plugins eventually slows down wordpress. This code will do up the task. Thanks Arup Bro for sharing with us.
Let me know if you face any problem with the code.
Hey Thanku for this script.
How may i add thumbnails to it and give look like jetpack related posts.
Regards
Glad to see that you are using the script on your blog . To add images in thumbnails you have to add code that fetches the post featured image and add styling to get Jetpack like look.
So May You Tell me steps to do that regards
hi Arup!…..pls would be glad if you could add featured image thumbnails code!
Awaiting!!!
I’ll add the updated code soon. Subscribe WPTron to get notified when the updated script posted.
Add me to the list of people who want to see the code updated with thumbnails. That would be awesome. I just subscribed with my fingers crossed.
Hey Arup Ghosh Thnku for script.
how can i change position of related posts?
Pls Reply fast
Regards.
I don’t understand your question properly. What do you mean by the position change of related posts?
Thanks for the effort to provide this code. But it’s not working on my site. Can you please have a look and resolve it?
What you are getting with the code?
Hey thanks for this!
However, is there anyway to make it more complex? Maybe make it related based on Categories & Tags combined?
Thanks!
where the preview ?
its better if you add the preview
Yes, it’s better to have a preview, but images sometimes are deceiving.
May I know How many related posts will show in one post by this code???
By default the code will show 4(max) related posts per article but you can change the number on `’showposts’ => 4,` .
This is exactly what I’m looking for. It works perfectly, thank you.
Thanks for sharing your feedback.
Hello Sir, Thank you for sharing codes with us. I have done little modification of code snippet and CSS in two ways. I hope you gotta like this to see; you can visit: bit.ly/2HqCxDd
Thanks, Aichuk for sharing your version Genesis related posts code. I also checked the Genesis child theme you developed, it looks great.
Thanks, Arup.
I was looking for a without plugin method.
Thanks again…
Nice articles
I am not a coder. Third-party plugins slow down the WordPress website. Thanks for your easy tutorial. Can you write an article, that how to add thumbnails in related posts. It’ll help a lot.
Thanks but i need theme related posts codes that shows without any thumbnail
Thanks for this code man
Hi thanks for your article, it works fine but i’m Wondering if is possible to add the post excerpt as well
Hi Vince,
Glad to know, you found this helpful. I’ll add that ASAP.
first of all great post, I have implemented this on my website, and it works is there any way to show post thumbnails
thank you
very useful information, Thank you
Is there a demo for your work? And will this technique work for the latest Genesis version?
No demos are available currently for the related post’s code. It was working fine with Genesis 2.3
Thanks for the article.
It solved my problem.
first of all great post, I have implemented this on my website, and it works is there any way to show post thumbnails… thanx for share this
Hi, Arup sir thanks for code of related post… this code is working fine but I want to show related post from parent category only and not from all selected category.. how can I achieve this? please sir help
I’ve not tested but changing
wp_get_post_categories($post->ID )
toget_category_parents($post->ID )
may work.code kaha hea
Hi, thank you for pointing out the issue. We have updated the code block. If you are still facing the issue go to : https://gist.github.com/arupgsh/a65f5b38031acf2a809d#file-related-post-category-php .
Code works great for me on normal posts, but on another website I only use custom post type posts, and it will not show anything. What do I need to change in the code to have it working with CPT posts?
Hi, Thank you but i have questions about it. I don’t want to count 1,2,3. How can i remove it. And second question is that i want to title h3 is ok but related posts should be h2. How can do it?
You can remove $count++ from line 36 the code will look something like following.
To make the related post titles h2 add
tag inside the list tag.
first of all, great post. i have 3 category and in each have 10 content. for each content i create tags. now this code what does work? and please tell maybe has wrong for show relate content? thanks
Hello. Thanks for this good post.
I have some more specialized questions.
What is the best way to find links:
1- Within a category
2- Within all categories of the entire site
3- Within all tags
4- Within the tags of a category
5- If we assume that the current article is placed in a category that contains 100 other articles in the same category, it is undoubtedly better to look for common tags in the same category, but the question is which tags should be displayed in priority. are. Maybe my tagging is wrong because some articles may have 7 tags and others 2 tags and even one.
Please guide me completely as I am really confused.
You can play with the $args [line 13] parameters to achieve related posts based on the criteria you mentioned (default case #1). Also for more advanced queries you can look into the documentation of `WP_Query` class.
https://developer.wordpress.org/reference/classes/wp_query/