• Resolved Sharon

    (@prettybiddy)


    Hi – Thank you for this wonderful theme.
    How would I modify alx_related_posts function to exclude certain Categories from the related posts? I use the related by Tag option to show posts related by Tag underneath a post. I would like to exclude blog posts that match in 2 Categories from being shown. How would I tweak the code to do that?
    Thank you.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi Sharon. Took a quick look around and found this article. Haven’t tried actually applying it to the function but might give you some ideas.

    Thread Starter Sharon

    (@prettybiddy)

    Hello – Thank you for that – I will take a look!

    Hi Sharon. Just checking to see if you were able to resolve your question.

    Thread Starter Sharon

    (@prettybiddy)

    Hello – I haven’t had a chance to look into it yet but will in the next few days – thanks for asking

    Hi Sharon. I think I have something that might work for you. This involves editing the functions.php file. After you set the initial categories to exclude, you’ll need to remember to update the function if you need to adjust the categories.

    1. In Post – Categories, edit each category you want to exclude and get the “tag_ID=” number from the URL.
    2. Copy the entire Related Posts function from the parent functions.php to your child theme functions.php.
    3. Find the following code at the end of the “//Related by tags” section of the function:

    }
      if ( !$tags ) { $break = true; }
      }

    4. Between the code line and the closing bracket, add three new lines of code so it looks like this:

    }
      if ( !$tags ) { $break = true; }
      else {
        // Define categories to exclude
        $args['category__not_in'] = array( 1,2,3 );
      }

    5. Replace the ( 1,2,3 ) with the category IDs you selected in #1 above.
    6. Test.

    Let me know how that works.

    Thread Starter Sharon

    (@prettybiddy)

    Hello – Thanks so much for doing that – I will try that today and let you know how it goes!

    Thread Starter Sharon

    (@prettybiddy)

    Hello – That seems to be working nicely, thank you! Are you a Hueman theme author by the way?

    Glad is’t working for you. Nope, not a Hueman theme author. Just someone who uses the theme and likes to help other users as a way to give back to the WP community and Alex in particular for contributing the theme.

    Thread Starter Sharon

    (@prettybiddy)

    You are a gentleman and a scholar and I thank you :-).

    Thanks for the kind words. If you’re satisfied with the results please mark this topic as resolved.

    Thread Starter Sharon

    (@prettybiddy)

    Will do.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘alx_related_posts function’ is closed to new replies.