0

How can I limit related entries to a specific category, while matching the relation on specific category groups?

Obviously this would be the code for it

<ul>
{exp:channel:entries related_categories_mode="yes" channel="news" custom_fields="yes" limit="10" category="16" category_group="7|1"  uncategorized_entries="no"}
    <li>
        <a href="/{language_code}/solutions/nieuws/detail/{news_url_title_{language_code}}/{entry_id}">{news_title_{language_code}}</a>
    </li>
{/exp:channel:entries}
</ul>

but the category parameter is not supported with using related_categories_mode.

EDIT - additional clarification: Category group is used to make sure that only in entries that have the same categories in those groups are presented as related entry.
E.g: the news channel has 5 category groups, but only 2 of them are relevant for the relationship, the others are e.g. audience segment (partner, customer, supplier) or message type (press release, item, blog) In this case only the related entries need to be shown if their audience segment is 'customer' (multiple can be selected)

2
  • If you want to specify a category_id, then what purpose does using related_categories_mode (or even specifying a category_group) serve? Maybe I'm not understanding the question. Commented Nov 12, 2015 at 17:28
  • added some additional explanation, it has a valid use case as you can see Commented Nov 12, 2015 at 17:37

1 Answer 1

0

It can be done, but it is a bit of a hassle... This is what I eventually came up with to tackle this use case:

Same code as above, but with an additional parameter that excludes all entries that are not assigned to the category that is to be shown.

<ul>
{exp:channel:entries related_categories_mode="yes" channel="news" custom_fields="yes" limit="10" category_group="7|1" uncategorized_entries="no"
entry_id="not {exp:low_variables:single var='elv_excluded_entry_ids' preparse:target_channel='news' preparse:from_subsite='innoviso'}"}
    <li>
        <a href="/{language_code}/solutions/nieuws/detail/{news_url_title_{language_code}}/{entry_id}">{news_title_{language_code}}</a> 
    </li>
{/exp:channel:entries}
</ul>

That exclusion is done via a (Early) Low Variable that presents a piped list of Entry IDs to be excluded:

{if from_subsite=="innoviso"}
{exp:dandy_cat:entries channel="{target_channel}" category="(17)&(not 16)" dynamic="no"}
{entry_id}|
{/exp:dandy_cat:entries}
{/if}
{if from_subsite=="solutions"}
{exp:dandy_cat:entries channel="{target_channel}" category="(16)&(not 17)" dynamic="no"}
{entry_id}|
{/exp:dandy_cat:entries}
{/if}

I still believe there should be an easier way (eg support the category parameter for related_categories_mode). If anybody has any better solutions let me know!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.