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 parent categories on a sub-category page.....

June 14, 2012 1:48pm

Subscribe [2]
  • #1 / Jun 14, 2012 1:48pm

    Patrick Hvid

    62 posts

    I have a perhaps strange need for a site I’m building.
    In a few channels I’m using parent categories with one level of childs.
    Looks something like this:

    *Computers
    *-PC
    *-Mac
    *Cellphones
    *-Android
    *-iPhone
    *-Others
    ...etc.

    On my page I let the parent category be the drop down menu for the sub’s to show, and the user only can select the sub.
    However it’s always possible that you tag the parent category instead of a sub, either because it’s relevant to all sub’s or by mistake.

    What I can’t figure out, and need some help with is either:
    -How can you, in a template include the parent category on a page for a sub
    -How can you make a selection of a parent also select the the sub’s
    -How can you make the parents unelectable

    The options above are listed in preferred order, so the top is the one I’d like to solve 😊

    /patrick

  • #2 / Jun 14, 2012 2:33pm

    Patrick Hvid

    62 posts

    Here’s a link to a page that should describe the way I’m using the categories.
    In swedish and with no content, but I think you’ll grasp the idea 😊

    Link to page

  • #3 / Jun 15, 2012 12:42pm

    Dan Decker

    7338 posts

    Hi Patrick,

    Thanks for the example page!

    Can you show the template code you are using? It would be helpful for us to get a look at where you are now, so we can get you a solid example.

    Cheers,

  • #4 / Jun 15, 2012 8:37pm

    Patrick Hvid

    62 posts

    Hi

    Right now I’m using gwcode categories to solve the navigation but as I understand I can’t use that to sort out the parent issue I need.

    <ul class="nav nav-tabs">
        <li class="{selected_empty}">
         <a href="/faq">Samtliga</a>
        </li>
       {exp:gwcode_categories channel="faq" site_id="4" max_depth="2" style="linear"}
        {if depth1_start}
         <li class="dropdown {selected_{output_path}}">
         <a href="#%22class=%22dropdown-toggle" class="dropdown-toggle">{cat_name}<b class="caret"></b></a>
        {/if}
        {if depth2_start}
         <ul class="dropdown-menu">
        {/if}
        {if depth == 2}
         <li><a href="/faq/category/{complete_path}">{cat_name}</a></li>
        {/if}
        {if depth2_end}
         </ul>
        {/if}
        {if depth1_end}
         </li>
        {/if}
       {/exp:gwcode_categories}
       </ul>

    The presentation is done in a very standard template (the same as I use without categories)

    {exp:channel:entries channel="faq" disable="{lv_shortcut_disable_default}" orderby="date" sort="desc" limit="2" paginate="bottom" }
        <h2>
         <span>p style="color:#0088cc;">{entry_date format='%Y-%m-%d'}</span>
         <a href="http://{url_title_path=">{title}</a>
        </h2>
    <p>    <div class="padded rounded_top clearfix"><br />
         {faq_entry}<br />
        </div><br />
        {paginate}<br />
         {if next_page}<a href="http://{auto_path}%22class=%22btn" class="btn btn-mini btn-inverse"><i class="icon-chevron-left icon-white"></i> Äldre</a>{/if}<br />
         {if previous_page}<a href="http://{auto_path}%22class=%22pull-right" class="pull-right btn btn-mini btn-inverse">Nyare <i class="icon-chevron-right icon-white"></i></a><br>{/if}<br />
        {/paginate}<br />
       {/exp:channel:entries}

    I guess I need to have a separate template to sort the issue I want but I can’t get my head around how that should be solved…


    /patrick

  • #5 / Jun 16, 2012 10:04am

    Patrick Hvid

    62 posts

    The solution (I guess) is to put the switch “category=”{category_id}|{parent_id}”” in the channel statement, but I can’t sort out where to get them…

    /p

  • #6 / Jun 16, 2012 7:04pm

    Patrick Hvid

    62 posts

    Hi

    I ended up creating a really ugly bastard to solve this, but perhaps there is a sleeker solution out there?
    This one WORKS the way I want it anyway 😊

    {if segment_2 =="category"}
    {exp:channel:category_heading channel="faq"}
     {exp:channel:entries channel="faq" disable="{lv_shortcut_disable_default}" category="{category_id}|{parent_id}" orderby="date" sort="desc" limit="2" paginate="bottom" }
      <h2>
       <span>p style="color:#0088cc;">{entry_date format='%Y-%m-%d'}</span>
       <a href="http://{url_title_path=">{title}</a>
      </h2>
    <p>  <div class="padded rounded_top clearfix"><br />
       {faq_entry}<br />
      </div><br />
     {paginate}<br />
      {if next_page}<a href="http://{auto_path}%22class=%22btn" class="btn btn-mini btn-inverse"><i class="icon-chevron-left icon-white"></i> Äldre</a>{/if}<br />
      {if previous_page}<a href="http://{auto_path}%22class=%22pull-right" class="pull-right btn btn-mini btn-inverse">Nyare <i class="icon-chevron-right icon-white"></i></a><br>{/if}<br />
     {/paginate}<br />
     {/exp:channel:entries}<br />
    {/exp:channel:category_heading}<br />
    {if:else}<br />
     {exp:channel:entries channel="faq" disable="{lv_shortcut_disable_default}" orderby="date" sort="desc" limit="2" paginate="bottom" }<br />
      </p><h2>
       <span>p style="color:#0088cc;">{entry_date format='%Y-%m-%d'}</span>
       <a href="http://{url_title_path=">{title}</a>
      </h2>
    <p>  <div class="padded rounded_top clearfix"><br />
       {faq_entry}<br />
      </div><br />
     {paginate}<br />
      {if next_page}<a href="http://{auto_path}%22class=%22btn" class="btn btn-mini btn-inverse"><i class="icon-chevron-left icon-white"></i> Äldre</a>{/if}<br />
      {if previous_page}<a href="http://{auto_path}%22class=%22pull-right" class="pull-right btn btn-mini btn-inverse">Nyare <i class="icon-chevron-right icon-white"></i></a><br>{/if}<br />
     {/paginate}<br />
     {/exp:channel:entries}<br />
    {/if}

  • #7 / Jun 18, 2012 5:04pm

    Dan Decker

    7338 posts

    Hi Patrick,

    If you are happy with the results, and the performance, then that is all that matters!

    Is there anything else I can assist you with?

    Cheers,

  • #8 / Jun 18, 2012 5:05pm

    Patrick Hvid

    62 posts

    I actually ended up doing it in another fashion, but I’m happy 😊

    With best regards,

    Patrick Hvid

  • #9 / Jun 20, 2012 2:47pm

    Shane Eckert

    7174 posts

    Hey Patrick,

    Glad to hear it! That’s awesome!

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases