yay Posted September 30, 2013 Share Posted September 30, 2013 (edited) I'm using the basic code to display the category image as a div background in header.tpl: {if $category->id_image} <div style="background: url({$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')|escape:'html'}) top center no-repeat;"> {/if} This works well with the top categories, but I would like the top category image to be displayed also when viewing subcategories, since they don't have any images of their own. Is there any way to do this? Preferably a solution that doesn't involve manually adding the top category image to all subcategories. Thanks in advance! Edited October 2, 2013 by yay (see edit history) Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted September 30, 2013 Share Posted September 30, 2013 1st, you should assign a smarty for parent category object Override CategoryController.php (don't forget to delete /cache/class_index.php) class CategoryController extends CategoryControllerCore { public function initContent() { parent::initContent(); // Load parent category object $parent_category = new Category((int)$this->category->id_parent); if(Validate::isLoadedObject($parent_category)) $this->context->smarty->assign('parent_category' , $parent_category); } } And then you can use the necessary variable of parent category object to get the image Link In your theme file (category.tpl) <img src="{$link->getCatImageLink($parent_category->link_rewrite, $parent_category->id_image, 'category_default')|escape:'html'}" alt="{$parent_category->name|escape:'htmlall':'UTF-8'}" title="{$parent_category->name|escape:'htmlall':'UTF-8'}" id="categoryImage" width="{$categorySize.width}" height="{$categorySize.height}" /> 1 Link to comment Share on other sites More sharing options...
yay Posted October 2, 2013 Author Share Posted October 2, 2013 (edited) Thanks for the reply! I got the parent category image to show in the subcategory, however the image disappeared in the parent category. Found a solution to that, but since I'm totally new to Prestashop it's probably anything but correct. {if $category->level_depth == 2} <!-- Ordinary category image for parent categories --> <img src="{$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')|escape:'html'}" /> {else} <!-- Use CategoryController to fetch parent category image for subcategory --> <img src="{$link->getCatImageLink($parent_category->link_rewrite, $parent_category->id_image, 'category_default')|escape:'html'}" /> {/if} Edited October 2, 2013 by yay (see edit history) Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 2, 2013 Share Posted October 2, 2013 I'm not sure if i'm understand, you've said "...however the image disappeared in the parent category..." what is mean ?But I'm glad you can solve the problem You can use id_image variable to check the availability of catagory image, or better use php function file_exists(PATH_TO_FILE) to check the image file existence Link to comment Share on other sites More sharing options...
borkafight Posted September 12, 2017 Share Posted September 12, 2017 Hi chaps! With the release of the new version PS 1.7 this question is actual again. Could you help me to cope with this issue? I would like to display parent category image of a product page on a product page. Thanks a lot! Link to comment Share on other sites More sharing options...
elenaso Posted June 2, 2021 Share Posted June 2, 2021 I try to do this in PS 1.7.7.4, but it does not work. I found the solution in this post: https://stackoverflow.com/questions/15968362/prestashop-how-to-find-category-id-image The problem was we need modify two functions in CategoryController.php: public function init() and public function initContent() Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now