Jump to content

[SOLVED] How to add an "IF no parent category" statement to hide the subcategory picture in category.tpl?


Recommended Posts

I came across an interesting issue.

I should be able to fix this with a tiny IF statement but can't figure out where to start...

I noticed that a thumbnail image is displayed at the top of the categories page for each of it's subcategories. 

This is fine but when you navigate into the subcategory itself, the same image is used - also shown at the top of the screen. Problem is ideally what you want to show at this point is a "widescreen" or "banner" version of that image, not a square one. 

So what I would like to implement is the following code in categories.tpl (at around line 15, just before the {if $category->id_image} line of code):

IF CATEGORY HAS A PARENT CATEGORY THEN DO NOT SHOW CODE BELOW

Can anyone assist? 

Link to comment
Share on other sites

Thanks Rocky!

That gets me half way there:)

What I need is:

---Parent Category 1: wide photo (THE MAPPING FEATURE HELPS ME WITH THIS)

---Parent Category 2: sub-category thumbnails (this is working as expected)

------Sub-Category 1: hide the photo altogether (not sure how to do this one...?)


I think the mapping solution only fixes the first problem?

Link to comment
Share on other sites

So you want to hide the category image on categories that don't have any subcategories? I think you can do that by changing lines 17-25 of category.tpl in your theme's directory from:

{if $scenes}
   <!-- Scenes -->
   {include file=$tpl_dir./scenes.tpl scenes=$scenes}
{else}
   <!-- Category image -->
   {if $category->id_image}
       <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
   {/if}
{/if}



to:

{if $scenes}
   <!-- Scenes -->
   {include file=$tpl_dir./scenes.tpl scenes=$scenes}
{elseif isset($subcategories)}
   <!-- Category image -->
   {if $category->id_image}
       <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
   {/if}
{/if}

Link to comment
Share on other sites

Here's a couple of other snippets of code you can try:

{if $scenes}
   <!-- Scenes -->
   {include file=$tpl_dir./scenes.tpl scenes=$scenes}
{elseif $category->id_parent == 1}
   <!-- Category image -->
   {if $category->id_image}
       <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
   {/if}
{/if} 



or:

{if $scenes}
   <!-- Scenes -->
   {include file=$tpl_dir./scenes.tpl scenes=$scenes}
{*{else}
   <!-- Category image -->
   {if $category->id_image}
       <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category')}" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
   {/if}*}
{/if} 

Link to comment
Share on other sites

Hi all, just an update.

I've been doing some more testing around these two different bits of code.

I think the first one is better. The second one only displays a "wide" category image that has been mapped. So in this regard the first one is less effort to maintain (for my situation anyway).

I will continue testing this and leave my progress in this thread for people who need to use this in the future.

Link to comment
Share on other sites

×
×
  • Create New...