Jump to content

Multiple Images 2


mickeyboy1

Recommended Posts

ok i shall try in here......i did post in theme development but didnt get any replies so i assume all the brains are in here :)

 

If i have ten subcategories that all use the same image, is there a way to only upload one image for them all to use or do i have to upload the same image for all the subcategories ???

 

thanks in advance mb

Link to comment
Share on other sites

Thank you pishkus for your reply,

The way i am setting up my site is that there will be around twenty main categories, each having another twenty subcategories.(roughly, i havent actually counted them but there is a lot)

The subcategories will all be the same, just with relevant products to the main category.

Uploading the same image for 20-30 subcategories is just a bit time consuming, and thought it might be easier if your could have an IF statement (or similar) to say something like:

If subcat is between 31 and 40 then choose image 4

If subcat is between 41 and 50 then choose image 5

etc

 

I know this context is not correct i am just trying to give you an idea of what i wanted to do.

Also, would it take up more server space having alot of the same images?

 

Thanks mb

Link to comment
Share on other sites

Ok, I get the idea.

I would do something like this:

 

Open file themes/your_theme/category.tpl, find lines like this:

<!-- Category image -->
<div class="content_scene_cat_bg"{if $category->id_image} style="background:url({$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')|escape:'html':'UTF-8'}) right center no-repeat; background-size:cover; min-height:{$categorySize.height}px;"{/if}>

We'll replace the second line with the following code:

{assign var="show_category_image" value=false}
{if $category->id_image}
  {assign var="category_image" value=$link->getCatImageLink($category->link_rewrite, $category->id_image, 'category_default')|escape:'html':'UTF-8'}
  {assign var="show_category_image" value=true}
{else}

  {$category_ids['file_1.jpg'] = [14,15,16]}
  {$category_ids['file_2.jpg'] = [13,17,18,19]}
  {$category_ids['file_3.jpg'] = [20,21,22]}

  {foreach from=$category_ids key=filename item=id_list}
    {if in_array($category->id, $id_list)}
      {assign var="category_image_name" value=$filename}
      {break}
    {/if}
  {/foreach}
  
{/if}
{if isset($category_image_name)}
  {assign var="category_image" value=$img_dir|cat:'some_other_dir/'|cat:$category_image_name}
  {assign var="show_category_image" value=true}
{/if}
<div class="content_scene_cat_bg"{if $show_category_image} style="background:url({$category_image}) right center no-repeat; background-size:cover; min-height:{$categorySize.height}px;"{/if}>
Edited by pishkus (see edit history)
Link to comment
Share on other sites

Hello again pishkus, thanks for that.

I have applied the changes but i get an error and white page.

The error is .....

Fatal error: Uncaught --> Smarty Compiler: Syntax error in template "C:\xampp\htdocs\prestashop1-6-14\themes\default-bootstrap\category.tpl" on line 70 "<div class="content_scene_cat_bg"{if $show_category_image} style="background:url({category_image}) right center no-repeat; background-size:cover; min-height:{$categorySize.height}px;"{/if}>" unknown tag "category_image" <-- thrown in C:\xampp\htdocs\prestashop1-6-14\tools\smarty\sysplugins\smarty_internal_templatecompilerbase.php on line 70

 

Is there anything i need to change in the code provided? 

 

Thanks mb

Link to comment
Share on other sites

ok i have changed the last line and also changed this 

{$category_ids['file_1.jpg'] = [14,15,16]}

to this 

{$category_ids['test_1.jpg'] = [12,13,16]}

Where i would like the image "test_1.jpg" in cats 12,13 and 16, but still not changing or showing image

Is this correct ??

 

Thanks mb

Edited by mickeyboy1 (see edit history)
Link to comment
Share on other sites

{assign var="category_image" value=$img_dir|cat:'some_other_dir/'|cat:$category_image_name}

$img_dir - /img/ folder of your current theme

$category_image_name - file name, e.g. test_1.jpg

some_other_dir/ would be needed if you kept your category images in a subfolder /default-bootstrap/img/some_other_dir/. You can change it to whatever you need.

Link to comment
Share on other sites

Thanks for all your help so far pishkus,

 

my images are in the default folders.....so img/c (for the category images)

 

By the way, this is needed for the subcategory images .

 

I have my site set out using main categories on the homepage but dont actually show main category images, only subcat and sub-subcat images

 

Main Cat1 has 

subcat1, subcat2, subcat3

Main Cat2 has

subcat1, subcat2, subcat3

 

So when you go into MainCat1 you will get a list of subcategories, these are the images i am trying to call

Also i just relised that these images are medium-default(in the subcategory list) but are category-default when in chosen subcategory page

Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...