I have content entries in a channel called resources.

Resources primary categories are whitepapers and downloads.

Secondarily, the entries are categorized by "brand"

What I want to do is grab the current category id (e.g. downloads) but then display the entries grouped by "brand"

This is my code.

{exp:channel:category_heading channel="resources"}
{!--grab main category we're viewing. E.g. we're viewing "downloads" in the "resources" channel--}
<?php $category = '{category_id}'; ?>

{!-- loop through the brands --}
{exp:channel:categories category_group="2" show_empty="no"}

    <h2 style="float:left; clear:both; width:100%;">{category_name}</h2>

    {!-- now display entries from this main category (e.g. downloads) that are also categorized under the current brands --}
    {exp:channel:entries category="<?php echo $category; ?> & {category_id}" channel="resources" disable="member_data|pagination|trackbacks"}

        <a href="{pdf}">{title}</a><br>



Where it says $category and category_id, only recognizing the latter. I can accurately print the $category to screen in the loop but the category= filter doesn't recognize it.


2 Answers 2


It looks like you have a mix of using php on input and output in the same template. Output while setting $category (EE tags run first, then output {category_id} for use in php), and input while echoing $category (PHP runs first and outputs $category as a string for use in an EE tag).

So you'll only be able to set the template for one or the other. You could use something like Stash to set the variables instead of php, or move the interior channel entries to an embedded template.


{exp:stash:set name="main_category_id" parse_tags="yes" trim="yes"}
    {exp:channel:category_heading channel="resources"}

{exp:channel:categories category_group="2" show_empty="no"}
    <h2 style="float:left; clear:both; width:100%;">{category_name}</h2>

        category="{exp:stash:get name='main_category_id'}&{category_id}" 
        status="not closed" 
        <a href="{pdf}">{title}</a><br>
  • nice screen name. I will look into this and update if this resolve it for me.
    – JaseC
    Jul 8, 2013 at 3:16
  • OK, Stash doesn't seem to be working either. In category_heading I have {exp:stash:set name="main_category_id"}{category_id}{/exp:stash:set} then in channel:categories I can print {exp:stash:get name="main_category_id"} to screen but I can't use it in the category= filter. My test category is '42'. As a control, if I just put that number in the category= filter, it works. I've tried switching PHP processing modes to no avail.
    – JaseC
    Jul 8, 2013 at 5:48
  • It sounds like the way you're headed with Stash is the way to go, but the parsing order is a problem. Try adding parse="inward" to your channel entries parameters. I'm updating the answer with an example. Jul 8, 2013 at 16:47

I would construct the filter/entry relationship differently to avoid nesting a channel entries loop inside the channel categories loop.


Pixel & Tonic's Playa add-on (http://docs.pixelandtonic.com/playa/)
Low's Seg2Cat add-on (http://gotolow.com/addons/low-seg2cat/docs)


• Resources {resources}
• Brands {brands}


• Resource Type
   - Downloads {downloads}
   - White Papers {white-papers}


• Resource Asset {resource_asset}
• Resource Brand {resource_brand}
   - Type: Playa
   - Field Label: Brand
   - Field Short Name resource_brand
   - Is this a required field? YES
   - Allow multiple selections? NO
   - Show expired entries? YES|NO
   - Show future entries? YES|NO
   - Channels: Brand
   - Categories: Any
   - Authors: Any
   - Statuses: Open
   - Limit entries to: All
   - Order entries by: Entry Title in Ascending Order



{exp:channel:entries channel="brands" dynamic="no" disable="..."}
    {if {exp:playa:total_parents} > 0}

    <h1>{title}{if segment_2} > {segment_2_category_name}{/if}</h1>

    {exp:playa:parents channel="resources" category="{segment_2_category_id}"}
        <a href="{resource_asset}">{title}</a><br />



I have not tested the overhead for this solution, so I do not know how it would compare to the Stash solution above.


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.