ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Category with descriptions including all entries

May 27, 2013 1:30am

Subscribe [2]
  • #1 / May 27, 2013 1:30am

    Stake

    22 posts

    I’m sure that the question has been asked but I’ve looked around and I can’t seem to find an answer.
    I’m using categories for a food menu. What I want to accomplish is:

    Cateogry name 1
    Category description

    Channel entry
    Channel entry
    Channel entry
    Channel entry
    Channel entry

    Cateogry name 2
    Category description

    Channel entry
    Channel entry
    Channel entry
    Channel entry
    Channel entry

    It seems harder than I thought, though I just might be missing a concept or two or overthinking it.

  • #2 / May 27, 2013 12:33pm

    Bhashkar Yadav

    727 posts

    Hi Stake,

    It would be fairly easy. You can accomplice it with the example code like:

    {exp:channel:categories category_group="x"}
     {category_description}
     {exp:channel:entries channel="channel_name" category="{category_id}"}
      {title}
     {/exp:channel:entries}
    {/exp:channel:categories}
  • #3 / May 27, 2013 1:13pm

    Boyink!

    5011 posts

    I’d suggest that if you don’t need content held in custom fields you can just use the category archive tag:

    http://ellislab.com/expressionengine/user-guide/modules/channel/category_archive.html

    I’ve used the approach listed by Bhashkar - but only when I wanted more than just entry titles. If you do use this code I’d strongly suggest using the disable parameter on the entries tag to turn off as much as you can, and keeping an eye on the total number of queries that the page generates. Nesting tags like that can become intensive if you have a lot of content.

  • #4 / May 27, 2013 2:11pm

    Bhashkar Yadav

    727 posts

    Yes, Michael is right.

    I think, tag optimization should always be a common practice for an EE developer for better performance. 😊 ...

  • #5 / May 27, 2013 6:13pm

    Stake

    22 posts

    Thanks Mike and Bhashkar,

    It seemed like I was on the right direction by using nested loops but I’ve come across another issue. Mike, since I do need more than just titles, category archive won’t work, unfortunately.

    Bhashkar’s code works but I need a little more granularity. For reference, my categories are nested so for example, I have a parent category of “grill” and burgers, sandwiches and sides under it.

    {exp:channel:categories channel="menu_items" category_group="2" style="linear" show="1"}
    {category_name}
    
    {category_description}
    
    
    {exp:channel:entries channel="menu_items" category="{category_id}" disable="trackback|pagination|member_data|custom_fields orderby="display_order" sort="asc"}
    {title}
    {description}
    {/exp:channel:entries}
    {/exp:channel:categories}

    I’ve added show=“1” (grill parent category) and returns the parent and the subcategories, which is fine however, it doesn’t return the subcategory name and its descriptions. I attempted to add each category ID invidually 15|16|17 but it returns nothing This leads me to believe that subcategories can’t be identified by category ID. Is this by design?

    I figured out a workaround but it involves flattening out the categories and repeating the code for each category.

    If there’s a better way, I’d like to know. Thanks for the help!

  • #6 / May 27, 2013 7:07pm

    Boyink!

    5011 posts

    Yea, you’re starting to push the capabilities of the native categories functionality.

    With the nesting you have going on, I start to wonder if you should be using the new relationships field instead.

  • #7 / May 27, 2013 7:21pm

    Stake

    22 posts

    Thanks Mike, I’ll experiment with relationships though I haven’t done any in 2.6. I’ll either end up simplfying the categories or building relationships.

  • #8 / May 29, 2013 1:37am

    Stake

    22 posts

    Mike,

    I wanted to report that I “played” with the new relationships in 2.6 and I think I got it sorted out after trying to understand the new tagging concepts. I have it exactly the way I needed to display the information. I used 3 channels, one to hold the menu items, the main “parent category” and the “sub category.”

    Thanks for steering me in that direction. I really didn’t want to overly complicate this and thought categories would be the way to go but it looks like this is more flexible than the built in category system. I do like the fact you can use standard entries parameters to add some more control.

    Thanks!

  • #9 / May 29, 2013 9:26am

    Boyink!

    5011 posts

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases