0

I have a list of images in 4 different categories that I want to display on a search results page. My logic is that the pictures are to be displayed under 2 conditions, 1 - it is in its respective category id, 2 - there are actually entries that have that category.

{if "{category_id}" == "1" &&  count >= "1"}
Image group 1 
{/if}
{if "{category_id}" == "2" &&  count >= "1"}
Image group 2 
{/if}

This code is not working,I think I'm messing up the syntax.

Some more code:

{exp:channel:categories channel="product" category_group="1" style="linear"   parent_only="yes" show="{embed:prod_cat}" show_empty="no"}
{if count == '1'}
<ul class="tabs-nav clearfix">
{/if} 
    <li>
        <a href="#tab_{category_url_title}">{category_name} Product<span class="indicator">        </span></a>
    </li>

    <li class="logo-strip">
        {!-- v neck tees --}
        {if "{category_id}" == "1"}
        <!-- Nike -->
        <img src="/images/logos/nike.jpg" class="float-left">
        <!-- Adidas -->
        <img src="/images/logos/adidas.jpg" class="float-left"> 
        <!-- Cat -->
        <img src="/images/logos/cat.jpg" class="float-left"> 
        {/if}

        {!-- long sleeve tees --}
        {if "{category_id}" == "2"} 
        <!-- Puma -->
        <img src="/images/logos/cat.jpg" class="float-left"> 
        <!-- Lacoste -->
         <img src="/images/logos/lacoste.jpg" class="float-left cat_2">
        {/if}

    </li>  

    {if count == total_results}
</ul><!-- end nav -->
{/if}
{/exp:channel:categories} 
3
  • I'm sorry, but I can't understand what you need. Can you, please, add more info? Thanks.
    – Sobral
    Jun 20 '14 at 13:57
  • Ok so I have a page with products on them. Each product is in one of 4 categories. I have a set of logos that correspond with the brand of that product. The category number (category id) is what determines what logo gets shown. So if the product is in category 1 then display these logos (image group 1). Now I also need the condition that these logos only show if there are products to view.
    – ObiWanKobi
    Jun 20 '14 at 14:21
  • Still need more information - is the code above standalone on the page or is it nested within the channel:entries loop? You state the page has products on, are you showing the logos in a sidebar as a collective, or within each product display? Is it in a {categories} variable pair, or {exp:channel:categories} tag pair? If in a channel:entries -> {categories} variable pair, remove the '&& count >= "1"' part of the conditional as it will only be hitting the conditional if there's a product that is in that category. Jun 20 '14 at 14:32
1

Your question doesn't say "what" isn't working so I'm going to add here what "should" work without knowing the extent of what you're doing.

{exp:channel:categories channel="product" category_group="1" style="linear" parent_only="yes" show="{embed:prod_cat}" show_empty="no"}
    {if category_id == "1"}
        Image group 1 
    {/if}
    {if category_id == "2"}
        Image group 2 
    {/if}
{/exp:channel:categories} 

Since you have the parameter show_empty="no" set, categories without entries shouldn't be returned. {if category_id == "1"} then controls which image shows for the category ID.

If results are not returning correctly, it's possible the show="{embed:prod_cat}" parameter is causing your problems.

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.