2

I'm certain this question must have come up before, but can't find any mention of it.

I need to filter out entries that are assigned to a parent category. I'm using this tag

{exp:channel:entries channel="blog" dynamic="no" limit="3" category="not 32"}

but this includes those entries categorised with child categories of category 32, and will only filter out those entries that are assigned just that one specific category. I want to retain the Auto-assign parent category functionality for my entries.

Any ideas how I could achieve this?

2

We really need a parameter to do this. Unfortunately, we don't have. So, while this:

{embed="pages/.entries"
    to_exclude="{exp:channel:categories style='linear' backspace='1' show='32'}{category_id}|{/exp:channel:categories}"
}

On your embed:

{exp:channel:entries channel="blog" dynamic="no" limit="3" category="not {embed:to_exclude}"}
| improve this answer | |
0

I had a very similar issue a few months ago. We resolved it by using Solspace Primary Category and a custom plugin. Barring a plugin, you can accomplish it with the Active Record plugin and Stash:

First, use Primary Category to assign the main category for each entry. Then drop this in your template (note how the Stash code at the top is all on one line):

{exp:stash:entry_ids parse_tags='yes' parse_conditionals='yes' no_results_prefix='ar'}{exp:activerecord select='entry_id' from='exp_primary_category' where="primary_category_id != '32'"}{entry_id}{if total_results > 1}|{/if}{if ar:no_results}0{/if}{/exp:activerecord}{/exp:stash:entry_ids}

{exp:stash:parse process='end'}
    {exp:channel:entries
        entry_id='{stash:entry_ids}'
    }
        {!-- channel entry data --}
    {/exp:channel:entries}
{/exp:stash:parse}

That will output only the entries that do not have category 32 assigned as their primary category.

Stash is used so we can create a pipe-delimited list of entry IDs early in the template parsing, then use it later on in the channel entries tag.

| improve this answer | |
0

In the end I used the Child Categories plugin to query all the child categories of a given parent, an feed that into the category="" param in exp:channel:entries. Not very elegant but works.

http://devot-ee.com/add-ons/child-categories

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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