We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to show entries with categories hierarchical

How Do I?

The Tactile Group's avatar
The Tactile Group
118 posts
8 years ago
The Tactile Group's avatar The Tactile Group

Hi All,

I set up categories hierarchical structure like:

Cat 1
--- Cat 2
--- Cat 3
--- Cat 4
Cat 5
--- Cat 6
--- Cat 7

And with entries, I would like to display as follow format:

Cat 1
--- Cat 2
      --- entry 1
      --- entry 2
--- Cat 3
      --- entry 3
--- Cat 4
      --- entry 4
Cat 5
--- Cat 6
      -- entry 5
--- Cat 7

I am using the following code, I could display all categories but not entries

{exp:channel:categories category_group="3" parent_only = "yes" style="linear"}
<h2>{category_name}</h2>
       {exp:gwcode_categories channel = "education_standard" cat_id="{category_id}" style="linear" entry_count="yes"}
{if !depth1_start}<h3>{cat_name} {cat_id} {entry_count}</h3>{/if}
  {exp:channel:entries channel="education_standard" category='{cat_id}' dynamic="no"} 
   {title} 
  {/exp:channel:entries} 
 {/exp:gwcode_categories}
{/exp:channel:categories}

I found that the {cat_id} is not pass to exp:channel:entries. If I hard code {cat_id}, i.e. {exp:channel:entries channel="education_standard" category='21' dynamic="no"}, the {title} will come up. Does anyone know why I could pass the dynamic category id to exp:channel:entries, so that it display the entries?

Thanks, Angela

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
8 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Angela, something quick to try:

{exp:channel:entries channel="education_standard" category='{cat_id}' dynamic="no" parse="inward"}
       
The Tactile Group's avatar
The Tactile Group
118 posts
8 years ago
The Tactile Group's avatar The Tactile Group

Hi Pedro,

No luck on adding parse=”inward”, cat_id still not pass to {exp:channel:entries} tag

Thanks, Angela

       
Pedro Guimaraes's avatar
Pedro Guimaraes
170 posts
8 years ago
Pedro Guimaraes's avatar Pedro Guimaraes

Angela, I took a closer look at the code and the issue is that you’re nesting a channel entries tag inside a channel categories tag. You’ll need to remove the channel entries and do it with an embed:

{embed="embeds/your-embed" cat_id="{cat_id}"}

Then in your embed you’ll have the following:

{exp:channel:entries channel="education_standard" category='{embed:cat_id}' dynamic="no"} 
{title} 
{/exp:channel:entries}

Hope that works for you!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.