coalesce Posted December 7, 2009 Share Posted December 7, 2009 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 More sharing options...
Ardian Yuli Setyanto Posted December 8, 2009 Share Posted December 8, 2009 you can modify from Home featured module, this module using home category with this code $category = new Category(1); in line 66 prestashop/modules/homefeatured/homefeatured.php Link to comment Share on other sites More sharing options...
coalesce Posted December 8, 2009 Author Share Posted December 8, 2009 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 More sharing options...
Ardian Yuli Setyanto Posted December 8, 2009 Share Posted December 8, 2009 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 More sharing options...
Ardian Yuli Setyanto Posted December 8, 2009 Share Posted December 8, 2009 And maybe you have to replace this line $category = new Category(5); $category = new Category(6); by $category = new Category(intval($_GET['id_category'])); Link to comment Share on other sites More sharing options...
coalesce Posted December 8, 2009 Author Share Posted December 8, 2009 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 More sharing options...
coalesce Posted December 8, 2009 Author Share Posted December 8, 2009 One note so the extra {/if} on the category.tpl page will break the category page. Link to comment Share on other sites More sharing options...
tutygr Posted December 10, 2010 Share Posted December 10, 2010 Thanks to both of you for that code! Link to comment Share on other sites More sharing options...
madnessr Posted April 8, 2016 Share Posted April 8, 2016 How use this code for many category - 2, 3, 5, 10, etc.? {if $category->id_category == 22} Link to comment Share on other sites More sharing options...
Recommended Posts