Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #275515

    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

    • This topic was modified 10 years, 5 months ago by Adenadoume.
    #275519

    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

    #275527

    Fastest reply ever and it works, you’re the best!

    Is there a way I could insert this in my child theme?

    Thanks

    #275535

    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

    #275545

    Yep works fine!

    Thanks a lot!!!

    #275549

    Hi!

    Great, glad it works :)

    Best regards,
    Peter

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Related posts based on category’ is closed to new replies.