In my gallery site i want to show other pictures under the current picture (in single post). I seen more codes but it i asks to specify the category, but i dont want want specify the category manually in the code I want the code itself to get the category ID or name.It would be much easier for me if i get full posts instead of post title so that I can display it as in home and category
Leave a Reply
You must be logged in to post a comment.
The question has already been asked and the answer has been posted too,
How to display related posts from same category?
Add this code inside your single.php after a loop wherever you want to show related post,
It will display related post from the same category with the post excerpt and title ,
however if want this code to display just the title of related post then remove this line,
Here is another clean and very flexible option:
Put this code in your functions.php file
Now you can simply call the function anywhere in your site using:
You may want to remove the list elements or style them as per your need.
This is an advanced example for developers. It supports custom post types and custom taxonomies, including matches by multiple taxonomies.
The function
buildTaxonomyForRelatedPosts
essentially builds an array with this structure:https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters