0

I have a exp:channel:categories loop that is filtered by category group, and within that I have an exp:channel:entries loop that is filtered by category_id. This outputting the data that I expecting.

The issue is that I need to get a count on the entries loop, but all I am able to get is a count on the categories loop.

Here is a slimmed down version of my loops:

{exp:channel:categories style="linear" category_group="2"}          
    {exp:channel:entries channel="team" category="{category_id}"}
        {title} - {count}
    {/exp:channel:entries}
{/exp:channel:categories}

I need to get a count on the channel entries, not the channel categories.

0

Use an embed. Take your {exp:channel:entries} loop and put it in it's own template partial. Make a template group and template for it, something like embeds/myloop. You can then pass the category_id as a parameter.

http://ee2docs.com/templates/embedding.html

So your final categories loop will look like this:

{exp:channel:categories style="linear" category_group="2"}          

    {embed="embeds/myloop" cat_id="{category_id}"}

{/exp:channel:categories}

and your embed will look like this:

{exp:channel:entries channel="team" category="{cat_id}"}

    {title} - {count}

{/exp:channel:entries}
| improve this answer | |
  • That worked, thank you! Does it seem odd to you that not using an embed doesn't work? Just curious if I am experiencing a bug or not. Thanks again! – Peter Conklin Nov 9 '15 at 17:43
  • It is not a bug, it is a complication of the template parsing order. The templating engine is pretty complicated, and by putting it in an embed, the embed is run through the parsing engine separately. – jrothafer Nov 9 '15 at 17:46
0

Thanks for this - works great, though you need to add {embed:cat_id} to grab the variable.

{exp:channel:entries channel="team" category="{embed:cat_id}"}

    {title} - {count}

{/exp:channel:entries}
| 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.