Jump to content

[SOLVED] If Category=1 display code on product page


Recommended Posts

I'm trying to display some simple code on my site if a product is within a certain category. Basically it just calls for an image that tells the user which category they are in.

I used this code on the category view (category.tpl) and it works, but it's crashing my the product pages:


{if $category->id AND $category->active}
          {if $category->id_category == 5}


{elseif $category->id_category == 6}


{else}
SHOP

{/if}



Maybe I need to add some code to product.php so it understand what it's pulling?

Any help would be greatly appreciated, the Smarty templates + Prestashop are new to me :)

Link to comment
Share on other sites

Hello Ardian,

Thank you for your reply. I don't think I totally follow?

So I'd have to use the code like this in the product.tpl file?


$category = new Category(5);
$category = new Category(6);

{if $category->id AND $category->active}
          {if $category->id_category == 5}


{elseif $category->id_category == 6}


{else}
SHOP

{/if}




Link to comment
Share on other sites

Hello Friend, sorry for this misunderstanding. I think you need to add {/if} in end of your code.
So I think its a complete code

$category = new Category(5);
$category = new Category(6);

{if $category->id AND $category->active}
       {if $category->id_category == 5}


       {elseif $category->id_category == 6}


       {else}
SHOP
       {/if}
{/if}

Link to comment
Share on other sites

Ardian thank you so much, I was just missing the one {/if}.

So if anyone needs to display something on a product on a per category basis, please use the code below for an example.

{if $category->id AND $category->active}

{if $category->id_category == 1}
PUT HTML HERE FOR CATEGORY 1

{elseif $category->id_category == 2}
PUT HTML HERE FOR CATEGORY 2

{else}
PUT DEFAULT HTML HERE

{/if}
{/if}

Link to comment
Share on other sites

  • 1 year later...
  • 5 years later...
×
×
  • Create New...