Tagged: blog page, related posts
Hello,
I would like to show at a single blog page under “You might also like” posts based on the current post’s category.
This has been asked before here: https://kriesi.at/support/topic/related-posts-based-on-category/
At the end, Dude has rewritten the code in related posts.php but the link he provides is no longer valid.
Could you please repost the rewritten code here?
Thanks
Hey Adenadoume!
Open up wp-content/themes/enfold/includes/related-posts.php and replace:
$tags = wp_get_post_tags($this_id);
with
$tags = get_the_category($this_id);
and
'tag__in' => $tag_ids,
with
'category__in' => $tag_ids,
Regards,
Peter
Fastest reply ever and it works, you’re the best!
Is there a way I could insert this in my child theme?
Thanks
Hi!
Yes, I think this is possible because we use the get_template_part() function to call the template. Just create an “includes” folder in your child theme directory and copy the modified related-posts.php into this folder – i.e. the file path should look like: wp-content/themes/enfold-child/includes/related-posts.php
Regards,
Peter
Yep works fine!
Thanks a lot!!!
Hi!
Great, glad it works :)
Best regards,
Peter