1

I have the following code:

<ul class="list">
    {exp:channel:categories 
    parent_only="no" 
    show_empty="no" 
    style="linear" 
    category_group="{if segment_1 == "cave"}3{/if}{if segment_1 == "clothing"}7{/if}{if segment_1 == "accessories"}8{/if}{if segment_1 == "brands"}2{/if}"}
        <li>
          <article>
            <a href="/{segment_1}/category/{category_url_title}">
              {category_image}
              <h2>{category_name}</h2>
            </a>
          </article>
        </li>
    {/exp:channel:categories}
  </ul>

But category_group doesn't seem to be working, I've tried the segment names in both double quotes and single quote and it still doesn't work any ideas?

1
  • 1
    Does it work if you just set category_group="3" parameter? Also what version of EE are you using? I assume the categories in question aren't empty (try show_empty="yes")? – Peter Lewis Aug 23 '13 at 21:48
1

Some days ago, I found a bug on parsing adjacent conditionals:

{if segment_1 == "foo"}{/if}{if segment_1 == [...]

I just had to separate the conditionals:

{if segment_1 == "foo"}{/if}
{if segment_1 == [...]

So, please, try this:

<ul class="list">
    {exp:channel:categories 
    parent_only="no" 
    show_empty="no" 
    style="linear" 
    {if segment_1 == "cave"}category_group="3"{/if}
    {if segment_1 == "clothing"}category_group="7"{/if}
    {if segment_1 == "accessories"}category_group="8"{/if}
    {if segment_1 == "brands"}category_group="2"{/if}
    }
        <li>
          <article>
            <a href="/{segment_1}/category/{category_url_title}">
              {category_image}
              <h2>{category_name}</h2>
            </a>
          </article>
        </li>
    {/exp:channel:categories}
</ul>

I hope it helps.

1
  • Seems we have the same bug, this works great, thanks! – Nick Sep 6 '13 at 8:25
1

I'd try Low's seg2cat and use {segment_n_category_group_id} http://gotolow.com/addons/low-seg2cat/docs

0
1

Christy's solution is a good one for sure.

But just in case your segments don't match the category group url_title exactly, try an embed or Stash. Here's the embed version.

In your current template, replace your current tag pair with this:

{embed="group/name_your_new_embed_template"
    cat="{if segment_1 == "cave"}3{/if}{if segment_1 == "clothing"}7{/if}{if segment_1 == "accessories"}8{/if}{if segment_1 == "brands"}2{/if}"
}

Then, in group/name_your_new_embed_template put a similar version of current tag pair, that's reads the values being sent for the cat parameter:

<ul class="list">
  {exp:channel:categories 
    parent_only="no" 
    show_empty="no" 
    style="linear" 
    category_group="{embed:cat}"}
    <li>
      <article>
        <a href="/{segment_1}/category/{category_url_title}">
          {category_image}
          <h2>{category_name}</h2>
        </a>
      </article>
    </li>
  {/exp:channel:categories}
</ul>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.