-
AuthorPosts
-
March 2, 2022 at 8:55 pm #1342917
Hi,
On a single blog page I would like to show “You might also like” posts based on the current post’s category.
Back in 2014 you answered how to solve this in thread: https://kriesi.at/support/topic/related-posts-based-on-category-2/
My question is whether there now in 2022 is another way to solve the issue without having to access the php files directly?
Thanks
March 3, 2022 at 3:56 am #1342938Hey BirgitteAlstrom,
Thank you for the inquiry.
The related posts section is still based on tags by default, so you will still have to edit the related-posts.php file as instructed on the previous thread. You can override the template file in the child theme directory if necessary.
Best regards,
IsmaelMarch 3, 2022 at 7:19 pm #1343045Hi Ismael,
Thank you for your reply.
I haven’t used the child theme before. I have just installed it now, but having problems with it, so I have opened another thread for that specific purpose: https://kriesi.at/support/topic/child-theme-does-not-look-like-parent-theme/
It is also first time I have to change in a php file, so I have the following questions:
1. When you say I have to edit the related-posts.php file is it then in the parent theme or in the the child theme? What do you mean by “you can override the template file in the child theme directory if necessary”?
2. Where do I find instructions on how to find the related-posts.php file and edit it?
Best regards,
BirgitteMarch 4, 2022 at 12:59 am #1343073Hi Birgitte,
1. It means by using a child theme you can modify some of the parent theme’s functionality. Please create a folder inside a child theme and name it includes, then copy the related-posts.php file from the parent theme (inside the includes folder) to the child theme’s includes folder.
2. I believe it’s in the link you posted above.Best regards,
NikkoMarch 4, 2022 at 1:10 am #1343074Hi Nikko,
Thank you for your reply.
Re. 1 above: In the case from 2014 ( https://kriesi.at/support/topic/related-posts-based-on-category-2/ ) they:
a. first modify the related-posts.php file in the parent theme
b. and then copy that modified file from the parent theme to the child theme.But I wonder whether it would be better in my case to:
a. first copy the original related-posts.php file from the parent theme to the child theme
b. and then modify the file in the child theme, so I don’t modify the related-posts.php file in the parent theme??And … is the only way to do this exercise via FTP or is there another way to do it?
Best regards,
BirgitteMarch 4, 2022 at 2:15 am #1343084Hi Birgitte,
The way WordPress works with parent themes and child themes is that it looks for the file with the same name in the child theme first and if the file is found it uses it, if not then it uses the one in the parent theme. For example, if the child theme contains both “includes/related-posts.php”, first it looks on the child theme if it has that file, if it does then it uses it, if not then it uses the one in the parent theme. So the results should be the same whichever you choose, the only difference is that the parent theme file is modified in the first one and not on the second one, but it doesn’t matter since the child theme’s file is used (also when there’s an update any modification on the parent theme will be removed).
Other than FTP, you can use cPanel. WordPress has a Theme Editor however you can’t create a file with it, you can just modify existing ones.
Best regards,
NikkoMarch 4, 2022 at 2:43 pm #1343159Hi Nikko,
Thank you so much. I really appreciate you have taken the time to explain how parent themes and child themes interact. Now I understand how it works :-)
Thank you for the tip regarding cPanel. I have now managed through cPanel to do the customization, and it works as described.
You are now welcome to close this thread.
Best regards,
BirgitteMarch 4, 2022 at 7:42 pm #1343194Hi Birgitte,
Great, I’m glad that Nikko could help you out. I’ll close this thread for now then, please open a new thread if you should have any further questions or problems.
Best regards,
Rikard -
AuthorPosts
- The topic ‘Related posts based on category 3’ is closed to new replies.