This topic has 6 replies, 4 voices, and was last updated 8 years by Andrei.

  • Author
  • #51815
     dolphspeed99
    Participant

    Hello,

    I need to use related posts to show posts that I manually select. Is there a way I can do this by modifying your related posts code? I don’t want to use another plugin for this, I like your code and want to stick with it. Another option that could work instead of manually select is to choose the related posts based on tags, so if I assign the tag “related-endomorph” to a post, I want the related posts to show posts with the same exact tag, “related-endomorph” and, if there aren’t a minimum of 3 articles to display, the code could look for other articles based on category/title or whatever algorithm you are using.

    I also know this isn’t subject to support as it is customization, but I would really appreciate some help, especially that I setup all the theme by myself without asking for help, and it could also be a very nice feature to implement in the following updates.

    Thank you!

    #52222
     Andrei
    Moderator

    Hi,

    The file you need to modify is the following ( you should copy it in your child theme, and make the modifications there ) : wp-content/themes/kleo/page-parts/posts-related.php

    You will see that at the beginning of the file there are some query args which you can modify to target your related posts. A few details about how you can modify those args can be found in the following page: https://codex.wordpress.org/Class_Reference/WP_Query

    Hope this information helps you achieve what you need.
    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #52246
     dolphspeed99
    Participant

    Understood, thank you so much for your help, I really appreciate it.

    #73958
     siloynet
    Participant

    I would also like to change the related posts from categories to tags. I check the wordpress codex page, but i am still confused.

    Could anyone please tell/guide me the change that need to be done

    COPY CODE
    //logic for blog posts
    if (is_singular('post')) {
    
        //related text
        $related_text = __("Related Articles", "kleo_framework");
    
        $categories = get_the_category($post->ID);
    
        if (!empty($categories)) {
            $category_ids = array();
            foreach ($categories as $rcat) {
                $category_ids[] = $rcat->term_id;
            }
    
            $args['category__in'] = $category_ids;
        }
    }

    Thanks

    #74882
     Andrei
    Moderator

    Instead of : $categories = get_the_category($post->ID); change it with $categories = array(‘YOUR_CATEGORY_ID’);

    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #112035
     hoops
    Participant

    hi! also want to display related articles by TAGS.

    what changes are needed in wp-content/themes/kleo/page-parts/posts-related.php ?

    thanks!

    #112207
     Andrei
    Moderator

    Hi @hoops, please check my earlier posts from this topic, you can find a link to the WP Query documentation where you have example for filtering posts by tags.

    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘KLEO’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?