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.

show just a child category with the category tag (not parent)

February 28, 2011 11:53am

Subscribe [3]
  • #1 / Feb 28, 2011 11:53am

    mprzybyla

    2 posts

    Hi,

    I’ve been having a tough time getting the categories tag to behave the way I need it to.  Basically, I want to show an intro in my template with the current category I am in, regardless of whether that category has a parent or not. 

    After the category I show the entries for that category.

    However, it seems as though the parent id is obligatory in the “show=id” parameter, so I must show the parent as well?

    Am I missing something? 

    It seems like it should be a pretty straightforward to just grab a child category by its ID.  The only way I’ve been able to achieve this is by doing something like the following:

    {exp:query sql="SELECT parent_id,cat_id FROM exp_categories WHERE cat_url_title = '{segment_4}'"}
    
        {!-- if the category has a parent, show the parent and the child --}
        {if parent_id != "0"}
        
            {exp:channel:categories channel="{channel_name}" show="{parent_id}|{cat_id}" style="linear"}
                {category_name_{lang_code}}
            {/exp:channel:categories}
        
        {!-- otherwise we are on a regular top level category --}
        {if:else}
        
        {exp:channel:categories channel="{channel_name}" show="{cat_id}" style="linear"}
            {category_name_{lang_code}}
        {/exp:channel:categories}
        
        {/if}
        
    {/exp:query}


    This kind of works, I get back the parent and the child.  But it would be nice to just be able to show a child category without having to also show its parent.

  • #2 / Mar 01, 2011 2:47am

    John Henry Donovan

    12339 posts

    mprzybyla,

    Basically, I want to show an intro in my template with the current category I am in, regardless of whether that category has a parent or not.

    How would the category:heading tag not work in this instance using the category description as an intro?

    {exp:channel:category_heading channel="{channel_name}"}
    
    <h1>{category_name}</h1>
    
    {if category_description}
    {category_description}
    {/if}
    
    {/exp:channel:category_heading}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases