Prestag0od Posted December 3, 2020 Share Posted December 3, 2020 In p1.6 I have put in the comments the code that displays the images of the subcategories at the top of the page in category.tpl so that it does not display them at all. But I want to display the images in a specific category (category ID) or only in those categories that have images and not display in those that do not have an image. Normally in those categories that do not have a photo, a default one that says no image is displayed. I do not want to display anything when the category does not have a photo. Can anyone help please? The code is here {if isset($subcategories)} {if (isset($display_subcategories) && $display_subcategories eq 1) || !isset($display_subcategories)} <!-- Subcategories --> <div id="subcategories"> <p class="subcategory-heading">{l s='Subcategories'}</p> <ul class="clearfix"> {foreach from=$subcategories item=subcategory} <li> <div class="subcategory-image"> <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img"> {if $subcategory.id_image} <img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'tm_medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" /> {else} <img class="replace-2x" src="{$img_cat_dir}{$lang_iso}-default-medium_default.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" /> {/if} </a> </div> <h5> <a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'|truncate:50}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'|truncate:350}</a> </h5> {if $subcategory.description} <div class="cat_desc">{$subcategory.description}</div> {/if} </li> {/foreach} </ul> </div> {/if} {/if} Link to comment Share on other sites More sharing options...
Guest Posted December 3, 2020 Share Posted December 3, 2020 {else} <img class="replace-2x" src="{$img_cat_dir}{$lang_iso}-default-medium_default.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" style="display:none;" /> {/if} Link to comment Share on other sites More sharing options...
Prestag0od Posted December 3, 2020 Author Share Posted December 3, 2020 1 hour ago, Guest said: {else} <img class="replace-2x" src="{$img_cat_dir}{$lang_iso}-default-medium_default.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" style="display:none;" /> {/if} Thanks for helping. I already tried this but even if i delete all this line the default image is still appearing. I dont know from where this default image is comming from!!!!!! Link to comment Share on other sites More sharing options...
Guest Posted December 3, 2020 Share Posted December 3, 2020 Clear cache! Link to comment Share on other sites More sharing options...
Prestag0od Posted December 3, 2020 Author Share Posted December 3, 2020 i clear cache after any modification. nothing happens. If i make some edit in other lines in subcataegory images div i can see the difference in front. Only when i edit this specific line i cannot see any difference! Link to comment Share on other sites More sharing options...
Guest Posted December 3, 2020 Share Posted December 3, 2020 Unfortunately, I'm not at the computer today. I would give you an exact solution tomorrow. Link to comment Share on other sites More sharing options...
Prestag0od Posted December 3, 2020 Author Share Posted December 3, 2020 ok thank you Link to comment Share on other sites More sharing options...
Guest Posted December 4, 2020 Share Posted December 4, 2020 Hi, {if $subcategory.id_image && Tools::file_get_contents($link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default'))} <img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" /> {/if} Link to comment Share on other sites More sharing options...
Prestag0od Posted December 4, 2020 Author Share Posted December 4, 2020 If i understand well i replace the code {if $subcategory.id_image} <img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'tm_medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" /> {else} <img class="replace-2x" src="{$img_cat_dir}{$lang_iso}-default-medium_default.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" style="display:none;"/> {/if} with your code {if $subcategory.id_image && Tools::file_get_contents($link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default'))} <img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" /> {/if} but i have excactily the same result. Link to comment Share on other sites More sharing options...
Guest Posted December 4, 2020 Share Posted December 4, 2020 screenshot Link to comment Share on other sites More sharing options...
Prestag0od Posted December 4, 2020 Author Share Posted December 4, 2020 Two categories at the end does not have image and they still showing the default image. Link to comment Share on other sites More sharing options...
Prestag0od Posted December 8, 2020 Author Share Posted December 8, 2020 On 12/4/2020 at 6:22 PM, Guest said: screenshot Dear friend, did tou check my screenshot? Thank you. Link to comment Share on other sites More sharing options...
Guest Posted December 8, 2020 Share Posted December 8, 2020 (edited) I'm sorry, I'm lying at home with a fever. I really don't have the strength and desire to sit at a computer. I only answer from a mobile phone. Covid-19. Edited December 8, 2020 by Guest (see edit history) Link to comment Share on other sites More sharing options...
Prestag0od Posted December 8, 2020 Author Share Posted December 8, 2020 Just now, Guest said: I'm sorry, I'm lying at home with a fever. I really don't have the strength and desire to sit at a computer. Covid-19. omg im really sorry. I hope to get well soon! Get a rest and you will be fine! Link to comment Share on other sites More sharing options...
Guest Posted December 10, 2020 Share Posted December 10, 2020 Hi. 1. open ./classes/Category.php add new function: public static function categoryImageExists($id_category) { if (file_exists(_PS_CAT_IMG_DIR_.$id_category.'.jpg')) {$imageExists = '1';} else {$imageExists = '0';} return $imageExists; } 2. open ./themes/default-bootstrap/category.tpl change to: {if $subcategory.id_image && Category::categoryImageExists($subcategory.id_category) == '1'} <img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" /> {/if} 3. clear cache result: Link to comment Share on other sites More sharing options...
Guest Posted December 10, 2020 Share Posted December 10, 2020 or category.tpl: {foreach from=$subcategories item=subcategory} <li> <div class="subcategory-image"> {if Category::categoryImageExists($subcategory.id_category) == '1'} <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img"> <img class="replace-2x" src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html':'UTF-8'}" alt="{$subcategory.name|escape:'html':'UTF-8'}" width="{$mediumSize.width}" height="{$mediumSize.height}" /> </a> {else} <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}" title="{$subcategory.name|escape:'html':'UTF-8'}" class="img"> <span alt="{$subcategory.name|escape:'html':'UTF-8'}" style="display:block;min-width:{$mediumSize.width}px;min-height:{$mediumSize.height}px;" /> </a> {/if} </div> <h5><a class="subcategory-name" href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'html':'UTF-8'}">{$subcategory.name|truncate:25:'...'|escape:'html':'UTF-8'}</a></h5> {if $subcategory.description} <div class="cat_desc">{$subcategory.description}</div> {/if} </li> {/foreach} result: Link to comment Share on other sites More sharing options...
Prestag0od Posted December 10, 2020 Author Share Posted December 10, 2020 (edited) Dear friend, thanks for helping. I hope you are better with your health. The function is working fine but even if some category does not have image it still keep the area empty. Is possible to fix that too? Edited December 10, 2020 by Prestan0ob (see edit history) Link to comment Share on other sites More sharing options...
Guest Posted December 11, 2020 Share Posted December 11, 2020 I can't advise you for your template I don't know. I don't understand what you really need. You have created your own function in PHP and you have the condition in the tpl file. You can use the condition in tpl as you need. You need to control HTML and css at least a little. 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