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.

List Categories, Subcategories, SubSubcategories still looking for a solution

May 08, 2011 11:32am

Subscribe [4]
  • #1 / May 08, 2011 11:32am

    Paradise

    84 posts

    Hi,

    i’m still looking for a way.

    I want to list the categories on a page. If you click on that page on a category you see the subcategories. If this subcategories have also subcategories i want to show them. If there are entries and not subcategories and want to show the entries.

    This is something i really still don’t know how to do it.
    Is there a addon for EE2 that now can do that?

  • #2 / May 08, 2011 11:38am

    Mark Bowen

    12637 posts

    Hi,

    Take a look at the excellent GWCode CatMenu and GWCode Categories.

    I’ve used the former to do exactly what you are wanting to do. I had to use some additional code to show entries if no other categories but this add-on made it WAY easier to do.

    Best wishes,

    Mark

    P.S. Sorry forgot to say that you may well be able to do everything you’re after with one or both of those plugins as I tested out an early version of the plugin and got everything working with a little extra code. There have now however been an awful lot more parameters and variables added in since I set my site up though.

  • #3 / May 08, 2011 12:14pm

    Paradise

    84 posts

    Hi Mark,

    i saw GWcode Categories, but from the description i tought it just shows categories for an entry (breadcrumb like)?

  • #4 / May 08, 2011 12:28pm

    Mark Bowen

    12637 posts

    Take a look at the GWCode CatMenu plugin instead. That’s actually the one that I used to do the same thing. In fact Leon actually created the plugin for me originally after I mentioned what I wanted to do. All done within a day, that’s one seriously fantastic developer! 😊

    Best wishes,

    Mark

  • #5 / May 08, 2011 12:37pm

    Paradise

    84 posts

    Do you have a site where i can see what you did?
    Do you make just one category group and but all cats and subcats in there or do you make multiple category groups for a channel and use the groups also as categories?

    Hm, don’t get it how to use the CatMenu for that. Cause it shows all categories on one page. Mabee i to tired to use my brain right now.

  • #6 / May 08, 2011 12:45pm

    Mark Bowen

    12637 posts

    Hiya,

    Unfortunately I can’t share the link to the site due to an NDA but it was pretty much what you are describing here. You will need to use the plugin parameters to retrieve exactly what you need but it definitely should be do-able.

    Perhaps have a word with Leon (the plugin author) as he is exceptionally helpful with these types of problems.

    Best wishes,

    Mark

  • #7 / May 08, 2011 5:10pm

    Leon Dijk

    131 posts

    Hi Bjorn,

    I just read your email asking me to join this thread.
    Thanks for the kind words Mark!

    Bjorn, did you take a look at the demo I set up here?

    It does this part of what you’re looking for:

    “I want to list the categories on a page. If you click on that page on a category you see the subcategories. If this subcategories have also subcategories i want to show them.”

    In the demo, I have combined two category groups into one menu (just to show what’s possible - in your case you’ll probably just use one category group). The first category group has a root category called “About” and that “About” category has two subcategories: “Company History” and “Company Information”.

    The second category group has a root category called “Services”. That category has 4 child categories..and some of them have child categories of their own. You can see them by clicking them. They open up automatically.

    This part of your question: “If there are entries and not subcategories and want to show the entries.” may be a bit harder to realize. When you say you want to show the entries, you mean you want to show the titles in the menu?

    Could you show us an example of what the output should look like?

  • #8 / May 08, 2011 6:10pm

    Paradise

    84 posts

    Hi,

    thanks for joining 😊

    Quick reply to the question. I have a static testing site here: http://www.odenwaldsport.de/0test/produkte.html
    The Produkte page shows the categories. If you click on “Studiogeräte” you see the subcats of “Studiogeräte”. If you click there on “Maschinen” you see a list of products.

    Now i go into your answere and check the demo 😊

  • #9 / May 09, 2011 3:29pm

    Leon Dijk

    131 posts

    Hi Bjorn,

    Ah, I see what you’re trying to do there. Forget GWcode CatMenu, that one has been created specifically for a navigation menu such as the one in the demo.

    Looking at testing site, when you click “Produkte”, you want to show all root categories for a channel called “produkte” for example. So, your URL will be something like this:

    domain.com/index.php/produkte

    It will then call the “index” template in your “produkte” template group.

    In that template, you’ll use this code:

    {exp:channel:categories channel="produkte" parent_only="yes"}
        <a href="http://{path=produkte/listing/category/{category_url_title}}">{category_name}</a>
    {/exp:channel:categories}

    That code will generate links to your root categories such as Studiogeräte and Fussballtraining, with links such as

    domain.com/index.php/produkte/listing/category/studiogerate

    Then, you’ll create a new template called “listing” where you’ll show the child categories using GWcode Categories for example.

    Here’s the code for that template with GWcode Categories:

    {exp:gwcode_categories cat_id="{exp:channel:category_heading channel='produkte'}{category_id}{/exp:channel:category_heading}" parse="inward" style="simple" incl_self="no"}
        {if "{last_child}" == "yes"}
            <a href="http://{path=produkte/products/category/{cat_url_title}}">{cat_name}</a>
        {if:else}
            <a href="http://{path=produkte/listing/category/{cat_url_title}}">{cat_name}</a>
        {/if}
    {/exp:gwcode_categories}

    What this code does: it looks at the current category being viewed and passes the category ID to the plugin, which then fetches all child categories.

    If there are 1 or more child categories, it will show them. If there are no child categories (it’s a last child category), it will link to a template called “products” where you will be able to show all entries for that category.

    Of course, you can rename the templates or template group any way you want.

    Does this make sense at all? And did I understand the question correctly?

    Cheers,
    Leon

    * Had to edit this post because the forum cut off my code :S
    PS Please make sure your channel name is surrounded by single quotes in the exp:channel:category_heading tag, or it won’t work because we’re also wrapping it between double quotes for the plugin.

  • #10 / May 11, 2011 1:41am

    Paradise

    84 posts

    Ok, looks like everything is working. Except the “first_only” thing i was asking on you site.

    Here i can show you the whole code. It’s more complicated than what you wrote. But your example was pointing me in the right direction 😊

    The thing is that i wan’t to show everything on one template and don’t want the category indicator in the url.

    {if segment_1=="produkte" AND segment_2==""}
    
    {exp:gwcode_categories channel="produkte" style="simple" depth="1"}
    
          <a href="http://{path=site_index}produkte/{cat_url_title}">{cat_name}</a>
    
    {/exp:gwcode_categories}
    
    {if:elseif segment_1=="produkte" AND segment_2!=""}
    
      {if segment_2_category_id}
    
        {if segment_3!=""}
    
          {redirect="404"}
    
        {/if}
    
        {exp:gwcode_categories cat_id="{segment_2_category_id}" style="simple" incl_self="no"}
     
          {if no_results}
            {embed="produkte/list"}
          {/if}
    
          <a href="http://{path=site_index}produkte/{cat_url_title}">{cat_name}</a>
    
        {/exp:gwcode_categories}
    
      {if:else}
    
        {exp:channel:entries channel="produkte" limit="1" disable="categories|category_fields|member_data|pagination|trackbacks"}
    
          {if url_title!='{segment_2}' OR segment_3!=""}
    
            {redirect="404"}
    
          {/if}
    
          {title}
    
          </div>
    
        {/exp:channel:entries}
    
      {/if}
    {/if}

    I don’t use the “channel:categories parent_only” like you showed it, cause that does not work if you have directly entries in the first category (category group > category > entry).

    Ok, i have the EE testsite now online: odenwaldsport . de/ 0ee/ produkte
    You need to remove the spaces. I don’t want google to index this testing link so i cut it up 😊

    So if there is just a depth of:

    Category group
    -category 1 (Studiogeräte)
    —subcat 1 (Maschinen)

    everything is fine.

    But if you look at Fussballtraining:

    Category group
    -category 1 (Fussballtraining)
    —subcat 1
    —-subsubcat 1

    then you also see “subsubcat 1”. But i want to show just “subcat 1” if you are in Fussballtraining.
    I want to show “subsubcat 1” if you are in “subcat 1”.

    Ok, now my head is near explosion because of to much logical thinking and i need a break *lol

  • #11 / May 11, 2011 4:23pm

    Leon Dijk

    131 posts

    Bjorn, sent you a PM with a download link. Let me know if that fixes your problem!

  • #12 / May 11, 2011 11:27pm

    Paradise

    84 posts

    Ok, here we have him.
    Leon - Men of the year 2011 😊

    It works. I don’t know since how long and how often i was trying to make a navi like that in EE.
    I tried all kind of category plugins and combinations. And now with your GWcode Categories it works and is that easy.

    Oh, and thanks to Mark for pointing me to GWcode Categories.


    The EE community is really the best. There is allways help and i know all the others (WP, Drubal, Joomla, Typo)

  • #13 / May 12, 2011 12:10am

    Mark Bowen

    12637 posts

    Yep Leon certainly is in my eyes add-on developer of the year. Fantastic code, fantastic turn around time and fantastic guy to boot 😊

  • #14 / May 12, 2011 3:59pm

    Leon Dijk

    131 posts

    Thanks guys! That means a lot to me 😊 Both plugins have gotten a lot better since the initial release thanks to the feature requests such as this and the great feedback from people like you two.

    Glad you’ve got everything working Bjorn! I like how you’ve found your own ideal solution just by getting a kick in the right direction and then evaluating what you could accomplish and what you were missing. Good job!

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

ExpressionEngine News!

#eecms, #events, #releases