Jump to content

Display specific category image on eg. home page


Recommended Posts

I want to publish a specific category plus category picture. No module, just a piece of code to put into my template such as:

 

 

{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}

 

How do I manage it?

 

Thanks in advance!

Link to comment
Share on other sites

it's because you haven't got defined $category variable, you need to put $category definition into the front controller smarty array (via assign)

 

How can I accomplish that?

Would you like to assist with an example or link?

Link to comment
Share on other sites

so you can easily edit the homefeatured.tpl file, you've got there:

$this->smarty->assign(array(
  'products' => $products,
  'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
  'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
 ));

 

add there 'category' => New Category (id),

where the id is an ID of category.

 

code:

$this->smarty->assign(array(
  'products' => $products,
  'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
  'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
  'category' => new Category(id),
 ));

Link to comment
Share on other sites

so you can easily edit the homefeatured.tpl file, you've got there:

$this->smarty->assign(array(
  'products' => $products,
  'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
  'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
 ));

 

add there 'category' => New Category (id),

where the id is an ID of category.

 

code:

$this->smarty->assign(array(
  'products' => $products,
  'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
  'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
  'category' => new Category(id),
 ));

I think vekia means that you should edit the homefeatured.php with code above, after that you can use category object in your template file.

 

Ok, that make some diffrence, thanks!

 

I get it to work when I change the code in the core file, but not when I try to change it for my specific theme. Any suggestions on that? (Have cleared the cache folder)

Link to comment
Share on other sites

Only .tpl files can be moved in your theme folder, for .php file this trick isn't works :(

 

If you wanted to accomplish the same thing, you would change the way I tried now? Or should I learn how to create a module. I am new to Prestashop as you can imagine.

Link to comment
Share on other sites

×
×
  • Create New...