Jump to content

[SOLVED] How to add an image to different category in the product page


Recommended Posts

Hello everyone,

Happy New Year.

I would like to add supplier logo images according to different category in the product page above the short description. For example: Category 3 is Nike, Category 4 is Gucci, and Category 5 is Puma. I want to put a logo according to the category. How can I do it?

Thank you for the help.

Link to comment
Share on other sites

Add the following code before the $smarty->display at the bottom of product.php:

$category = new Category($product->id_category_default);
$category_link = $link->getCatImageLink($category->link_rewrite, $category->id_image, 'medium');
$smarty->assign(array('category_name' => $category->name[intval($cookie->id_lang)], 'category_link' => $category_link));



Then add the following code somewhere in product.tpl in your theme's directory to display the category image:




This code assumes you have set up the default category of the product to be the category whose image you want to display.

Link to comment
Share on other sites

Add the following code before the $smarty->display at the bottom of product.php:

$category = new Category($product->id_category_default);
$category_link = $link->getCatImageLink($category->link_rewrite, $category->id_image, 'medium');
$smarty->assign(array('category_name' => $category->name[intval($cookie->id_lang)], 'category_link' => $category_link));



Then add the following code somewhere in product.tpl in your theme's directory to display the category image:




This code assumes you have set up the default category of the product to be the category whose image you want to display.



Thank you very much for the codes Rocky,
I have my images named 3-exsmall.jpg, 4-exsmall.jpg, and 5-exsmall.jpg in a folder path:root/img/c/. How do I set the path to the images?

Thank you very very much for the help.
Link to comment
Share on other sites

  • 4 months later...

Rocky,

how could I enable the category image to be different according to the language? There are default images like 'en-default-category.jpg', I'd like to have some text images for bettertogether module. So I created images like 'en-6-category' and fr-6-category' but I don't know how to make it so show them accordingly. Thank you!

Link to comment
Share on other sites

To do that with friendly URLs turned off would be easy, since you can just add {$lang_iso}- before the image links. To do that with friendly URLs turned on would be difficult though, since you'd have to modify the .htaccess file to redirect the language to the right images. I'm not exactly sure how to do that.

Link to comment
Share on other sites

Yes, that would work. You'll need to change line 39 of category.tpl from:

<img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}" alt="" />



to:

<img src="{if $subcategory.id_category == 2 OR $subcategory.id_category == 3}{$base_dir}img/c/{$lang_iso}-{$subcategory.id_category}-default.jpg{else}{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}{/if}" alt="" />



This code will create static links for subcategories 2 and 3 and use the default dynamic links for the other subcategories.

Link to comment
Share on other sites

Oh, I am sorry, looks like I described my problem wrong. I need some different images for every language to be shown at certain categories (which are on promotion) above the breadcrumb, and show nothing on other categories. So I tried to use your code

getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium')}{/if}" alt="" />  



and it is trying to load mysite.com/-medium/.jpg.

Looks like there is something wrong quoting the code, I used the one you suggested to change it to.

Link to comment
Share on other sites

Worked it out now - I had to add the following code to category.tpl:

{if $category->id_category == 2}id|escape:'htmlall':'UTF-8'}-{$lang_iso}.jpg" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
{elseif $category->id_category == 3}
id|escape:'htmlall':'UTF-8'}-{$lang_iso}.jpg" alt="{$category->name|escape:'htmlall':'UTF-8'}" title="{$category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" />
{else}
{/if}



So now the categories 2 and 3 show specified images for each language and other categories show none.

Link to comment
Share on other sites

×
×
  • Create New...