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.

Any Categories Gurus Out There?

March 09, 2011 4:07am

Subscribe [4]
  • #1 / Mar 09, 2011 4:07am

    Mark Bowen

    12637 posts

    Hiya,

    Was just wondering if anyone can help point me in the right direction in order to get categories showing correctly on a site I’m producing?

    Let’s say for example that I have a category structure like this :

    Aluminium Fittings
      Caps
      Male / Female Adaptors
      Hose Jointers

    Brass Fittings
      Ball Valve
      Hose Repairer
      Nozzle
      Double Male Adaptor
          Flat Seated

    Miscellaneous
      Air Gun

    et al.

    Currently on the main home page I have it set up to only show the very top level categories i.e. Aluminium Fittings, Brass Fittings, Miscellaneous and so on and so forth.

    This is fine. I now click on one of those top level categories and it directs to a new page and shows that category as open so something like this :

    Aluminium Fittings

    Brass Fittings
      Ball Valve
      Hose Repairer
      Nozzle
      Double Male Adaptor
          Flat Seated

    Miscellaneous

    et al.

    Again this is all fine. On this page I have some SQL goodness going on which basically takes you to either another category listing page or the listings of items incase we have more sub-categories or what not.

    Again this is all fine.

    The problem I have is when I go to a single entry page for a product.

    Let’s say I have a product called Product One and it is located in the Brass Fittings->Double Male Adaptor->Flat Seated category.

    I cannot for the life of me get my categories sidebar to look like this :

    Aluminium Fittings

    Brass Fittings
      Ball Valve
      Hose Repairer
      Nozzle
      Double Male Adaptor
          Flat Seated

    Miscellaneous

    et al.

    This is what I want to show so that the user can see exactly what category they are in and all the other top level categories. All I can get to show on the single entry page is every single category opened which presents them with a very very long list as there are 181 categories on the site!

    Is there a way of doing this? Either with the built-in tags or perhaps a plugin maybe?

    I’ve tried to test nearly every single plugin I can find for categories but don’t seem to be able to find a way of doing this. If anyone knows of a plugin that can do this then please could you let me know? 😉

    If there is definitely no plugin that can do this on a single entry page then does anyone know how I could hide the categories that I don’t want to see perhaps using some Javascript?

    Normally I wouldn’t really like to go that route but at this stage I’m open to anything.

    Thanks for any help on this guys.

    Best wishes,

    Mark

    Moved to CodeShare Corner by Moderator

  • #2 / Mar 09, 2011 4:40am

    Mark Bowen

    12637 posts

    Oh yes one other thing is that at the moment all entries are only located in one single category. None are in multiple categories. Don’t know if that helps at all though.

    I was also wondering though on a separate note if it’s possible to do the same sort of thing if a product is in multiple categories though and just open / expand the categories where the product does exist?

    Thanks.

    Best wishes,

    Mark

  • #3 / Mar 09, 2011 4:52am

    Darren Miller

    103 posts

    Mark -

    1. What’s the URL format of your product detail page?

    2. What’s the URL format and exp:tag that gives you your second example?

    You may well need a plugin to make 1. display 2, but depending on what 2 is, the plugin may be quite simple.

  • #4 / Mar 09, 2011 5:14am

    iain

    317 posts

    I’ve done stuff like this with php in the past but only for assigning active states to multiple category items on a single entry page, might get some ideas going:

    First, build an array of all the selected category ids:

    <?php
        $active_ids = array();
        {categories}$active_ids[] = {category_id}; {/categories}
    ?>

    then something like this to show only top level categories, and embed subcategories on an in_array check:

    {exp:channel:categories channel="blah" parent_only="yes" show_empty="no"}
        <a href="http://{path=...}">{category_name}</a>
    
     
        <?php if(in_array({category_id}, $active_ids)) { ?>
              {embed="inc/.child_categories" cat_id="{category_id}"}
        <?php } ?>
    
    {/exp:channel:categories}

    Just thinking out loud, might help you out, might not… 😊

  • #5 / Mar 09, 2011 5:14am

    Mark Bowen

    12637 posts

    Hiya,

    Mark -

    1. What’s the URL format of your product detail page?

    http://www.example.com/products/details/product_one

    2. What’s the URL format and exp:tag that gives you your second example?

    http://www.example.com/products/listings/C27

    I’m currently using the dyno_cat plugin and a SQL query :

    {exp:dyno_cat:categories weblog="products" show_empty="yes" group_id="2" parse="inward" active_id="current"}
    {exp:query sql="
    SELECT COUNT(*) AS subcategories_count
    FROM exp_categories
    WHERE parent_id='{category_id}'
    "}
    {if subcategories_count > "0"}
    <a href="http://{path=">{exp:xml_encode}{category_name}{/exp:xml_encode} {category_count}</a>
    {if:else}
    <a href="http://{path=">{exp:xml_encode}{category_name}{/exp:xml_encode} {category_count}</a>
    {/if}
    
    
    {/exp:query}
    {/exp:dyno_cat:categories}

    Thanks for taking a look at this for me, much appreciated.

    Best wishes,

    Mark

  • #6 / Mar 09, 2011 5:23am

    Darren Miller

    103 posts

    I’m not familiar with dyno_cat, but you might get lucky and including the C27 into your product URL might be enough.

    e.g.

    <a href="http://www.example.com/products/details/C27/product_one">http://www.example.com/products/details/C27/product_one</a>

    If you don’t want to do that, you’re going to need something to lookup the first usage of a category for that product entry and somehow pass it to dyno_cat. If it will take it as a tag parameter you could have a little input PHP to find the category ID and inject it into the dyno_cat tag.

  • #7 / Mar 09, 2011 5:40am

    Mark Bowen

    12637 posts

    I’m not familiar with dyno_cat, but you might get lucky and including the C27 into your product URL might be enough.

    e.g.

    <a href="http://www.example.com/products/details/C27/product_one">http://www.example.com/products/details/C27/product_one</a>

    Unfortunately not. I did try that a while back in the hope that it might work but it messes a lot of other things up on the page such as related entries and what not. :-(

    If you don’t want to do that, you’re going to need something to lookup the first usage of a category for that product entry and somehow pass it to dyno_cat. If it will take it as a tag parameter you could have a little input PHP to find the category ID and inject it into the dyno_cat tag.

    Again unfortunately dyno_cat doesn’t allow for that kind of thing to be done. Looks like I’m getting scuppered here at every turn. When you first look at it all it seems like this is something that should work out of the box but it’s turning into a bit of an impossible hope now.

    Best wishes,

    Mark

  • #8 / Mar 09, 2011 5:45am

    Darren Miller

    103 posts

    Again unfortunately dyno_cat] doesn’t allow for that kind of thing to be done.

    Are you 100% sure about that? If it’s producing context-sensitive output simply based on URL segments, then it must be looking up the category at some point in the script.

    It should therefore be possible to pick at that bit of code to alter it to your own value.

    Hard to say without looking at the plugin but if I was you I’d follow the code execution through on the category listing page and see at what stage it filters to a category. You can then go about looking at options to adjust that value.

    best of luck!

  • #9 / Mar 09, 2011 10:44am

    Sue Crocker

    26054 posts

    Hi, Mark—this really is better suited for the CodeShare Corner - moving there for additional community support.

  • #10 / Mar 09, 2011 11:01am

    Mark Bowen

    12637 posts

    Hi Sue,

    Hi, Mark—this really is better suited for the CodeShare Corner - moving there for additional community support.

    Okay yep no problem. Hopefully the devs are seeing this though and perhaps adding more options to the categories tag pair though? 😉

  • #11 / Mar 09, 2011 11:22am

    Sue Crocker

    26054 posts

    The devs don’t normally read this forum, they pay attention to bugs and feature requests. Your best bet is to post a well crafted feature request, and put it in the form of a user story. In other words, why do you want the feature? Who benefits from it? That sort of thing.

  • #12 / Mar 09, 2011 11:34am

    Mark Bowen

    12637 posts

    Thanks Sue. Feature request now put in. 😉

    Best wishes,

    Mark

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

ExpressionEngine News!

#eecms, #events, #releases