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.

Should sorting by parent categories also display applicable children entries?

March 09, 2010 6:22pm

Subscribe [3]
  • #1 / Mar 09, 2010 6:22pm

    iamnick

    17 posts

    I’m trying to get a handle of categories and am stuck at the moment.

    I have a page where the user can sort by categories. At the moment, I am setting the page to only show parent categories. However, I need to show any entries applied to child categories of the chosen parent. Is it possible to show entries assigned to the children categories when selecting a chosen parent? Or, does it require the user to select both the parent and the children category when assigning?

    Does this make sense?

  • #2 / Mar 09, 2010 7:47pm

    iamnick

    17 posts

    Issue resolved, I found the setting for Auto-selecting parent when choosing a child. Just missed it previously.

  • #3 / Mar 09, 2010 8:02pm

    I’m also interested in knowing if there’s a slicker way of doing this.

    In any event, I’m just getting started with EE myself, but, I was able to accomplish something like this by using some nested queries:

    This will loop through all of the parent categories in the “events” channel, and send each category ID to a template:

    {exp:channel:categories channel="events" parent_only="yes" style="linear"}
        {embed="site/sub-list-categories-parents" parent_id="{category_id}"}
    {/exp:channel:categories}

    Here’s the template referenced above.  It will display the name of the category and list all of the entries in that category.  Then, it will call another template, which will do the same thing for it’s children.

    sub-list-categories-parents:

    {exp:query sql="SELECT cat_name, cat_id FROM exp_categories WHERE cat_id={embed:parent_id}"}
        <h2>Entries in parent category {cat_name}</h2>
    <p>    {exp:channel:entries  channel="events" category={embed:parent_id}}<br />
           <!-- whatever content you want to show --><br />
        {/exp:channel:entries}</p>
    
    <p>    {embed="site/sub-list-categories-children" parent_id="{embed:parent_id}"}<br />
    {/exp:query}

    Do the same thing for the children of the category called above…

    sub-list-categories-children:

    {exp:query sql="SELECT cat_name, cat_id FROM exp_categories WHERE parent_id={embed:parent_id}"}
        <h2>Entries in child category {cat_name}</h2>
    <p>    {exp:channel:entries  channel="events" category={embed:parent_id}}<br />
           <!-- whatever content you want to show --><br />
        {/exp:channel:entries}  <br />
    {/exp:query}

    I hope that’s useful for you.

  • #4 / Mar 09, 2010 8:04pm

    Issue resolved, I found the setting for Auto-selecting parent when choosing a child. Just missed it previously.

    Never mind then 😊

    Auto-selecting the parent category when selecting a child wouldn’t help in my particular situation, I’m glad it’ll do the trick for you.

  • #5 / Apr 20, 2010 11:19am

    RezwanR

    126 posts

    Am I correct in assuming that “channel” is a word you substituted for “weblog”?  I.e., you can (and did) change the “weblog” text in the Weblog multi-select menu to something else, such as “Section” or “Channel”, by going to the Control Panel > Admin > System Preferences > General Configuration, in the “Section Designation Word” field.

  • #6 / Apr 20, 2010 11:27am

    RezwanR

    126 posts

    And I’m out of my depth here. 

    I tried this code:

    {exp:query sql="SELECT category_name, category_id FROM exp_categories WHERE parent_id={embed:parent_id}"}
        <h2>Entries in child category {category_name}</h2>
    <p>{/exp:query}

    And got this error:

    MySQL ERROR:
    
    Error Number: 1064
    
    Description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    
    Query: SELECT category_name, category_id FROM exp_categories WHERE parent_id=
  • #7 / Apr 20, 2010 11:31am

    RezwanR

    126 posts

    Maybe there is a simple way.

    What I’m trying to do is have a category page that has quick links on top to sub-categories.  For example, the parent category is “about” and the subcategories are “the organization”, “history”, “get involved” and “in the press”.  So, on the main category page, I want people to see:

    parent category name (About)
    category description (blurb about us)
    Subcategory links, e.g., child category names, linkable (The Organization | History | Get involved | Press | Contact Info )

    I suppose I could show it nested?  And then create a class to show the nesting in a row?

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

ExpressionEngine News!

#eecms, #events, #releases