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 Category by Custom Category Field

June 21, 2013 9:36am

Subscribe [2]
  • #1 / Jun 21, 2013 9:36am

    futuristonline

    43 posts

    Hi
    Small issue and not sure if EE can do this. I have an eCommerce shop and have a page which lists all the categories. I want to be able to create a category in a category group but have it hidden from the displayed list until it goes live.

    {exp:channel:categories category_group="1"}
     <ul>
      <li><a href="http://{path=categories/index}">{category_image}</a></br><a href="http://{path=categories/index}">{category_name}</a></li>
     </ul>
    {/exp:channel:categories}

    So the above lists all the categories within the category group.

    I have put a custom category field in of “category_status” and set this to drop down to live and not live. Can I not then just use:

    {exp:channel:categories category_group="1" search:category_status="live" }
     <ul>
      <li><a href="http://{path=categories/index}">{category_image}</a></br><a href="http://{path=categories/index}">{category_name}</a></li>
     </ul>
    {/exp:channel:categories}

    ...in order to filter these so only the “live” categories???

    Thanks in advance.

    Steve

     

  • #2 / Jun 23, 2013 11:35am

    travisb

    172 posts

    I don’t think you’re going to get what you want from the channel:categories tag. I would use Stash add-on to have much more control, something like this:

    First use the channel:entries tag and categories tag pair with a conditional to only output category info where you have set the custom field to “live”. The outer stash:set:list caches that output into a variable array.

    {!--  Set the variable list --}
    
    {exp:stash:set_list 
     name="live_cats" 
     parse_tags="yes" 
     output="no"
    }
     {exp:channel:entries
      channel="the_channel_name"
      status="not closed"
      dynamic="no"
     }
      {categories category_group="1"}
       {if category_status == "live"}
        {stash:cstatus}{category_status}{/stash:cstatus}
        {stash:cname}{category_name}{/stash:cname}
        etc….
        
       {/if}
      {/categories}
     {/exp:channel:entries}
    {/exp:stash:set_list}


    Then output the variables in a list when you are ready using stash:get_list

    {!-- Output the variables --}
    
    {exp:stash:get_list 
     name="live_cats" 
     unique="yes"
     match="#^live$#"
     against="cstatus"
    }
     <li>{cstatus},  {cname},  + any other variables however you need to format them…</li>
    {/exp:stash:get_list}

     

  • #3 / Jun 24, 2013 4:03am

    futuristonline

    43 posts

    Thanks for that. I’ll have a look at Stash and try it on the test server for the site and see what results I get.

    Again, thanks.

    Steve

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

ExpressionEngine News!

#eecms, #events, #releases