ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

UNrelated Categories

April 04, 2012 3:11pm

Subscribe [1]
  • #1 / Apr 04, 2012 3:11pm

    entrepreneurhip

    1 posts

    I have a unique requirement for related entries and am at a loss for how to implement the corresponding logic.

    We have two category groups: SECTOR and GEOGRAPHY. The requirement is to list “related” entries where SECTOR matches the current entry but GEOGRAPHY does NOT.

    i.e. CurrentEntry:Sector = RelatedEntries:Sector AND CurrentEntry.Geography != RelatedEntries:Geography

    As I’m new to EE, I’ve discovered how to setup basic related entries but am not sure how to incorporate this additional logic. Any help would be greatly appreciated!

    {exp:channel:entries channel="blog" limit="4" related_categories_mode="yes" custom_fields="yes"}
         <h4>{title}</h4>
    <p>{/exp:channel:entries}

  • #2 / Apr 05, 2012 12:14pm

    Dan Decker

    7338 posts

    Hi entrepreneurhip,

    Welcome to ExpressionEngine and the Forums!

    You are most of the way there! You can then supply the category= parameter with the “not” qualifier to exclude “Geography”.

    {exp:channel:entries channel="blog" limit="4" related_categories_mode="yes" custom_fields="yes" category="not 4"}
         <h4>{title}</h4>
    <p>{/exp:channel:entries}

    You will substitute “4” with the category ID number for your “Geography” category. The ID number can be found under Admin->Channel Administration->Categories

    Cheers,

  • #3 / Apr 05, 2012 1:03pm

    entrepreneurhip

    1 posts

    Thanks Dan! I’ve tried this setting but (correct me if I’m wrong) it appears to simply ignore this category from the matching process. Our requirement is a little more detailed. We want to return entries that are NOT equal to the current entry’s value for this particular category.

    For Example:

    Current Entry: SECTOR = Mobile, GEOGRAPHY = Europe

    Entry 1: SECTOR = Mobile, GEOGRAPHY = Asia
    Entry 2: SECTOR = Mobile, GEOGRAPHY = Africa
    Entry 3: SECTOR = Mobile, GEOGRAPHY = Europe

    In this scenario, only Entry 1 and Entry 2 should be returned as “related entries” because their SECTOR matches the SECTOR for the current entry but their GEOGRAPHY does NOT match the GEOGRAPHY of the current entry. Currently all three are returning.

  • #4 / Apr 06, 2012 4:19pm

    Kevin Smith

    4784 posts

    Hi entrepreneurhip,

    I see what you’re talking about. Yes, that’s a bit more complicated. There’s actually not a built-in way to do that, but you should be able to accomplish it. It’s a bit outside the scope of what we can offer here in support, but let me take a stab at offering you a solution:

    You could try using the Query Module to retrieve the category ID of the current entry and then use the result in a Channel Entries tag to exclude that category ID from the results. The only thing I’d be careful about is that an entry might have more than one category assigned to it, so you’d need to account for the possibility of the Query Module returning more than one category ID per entry.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases