Jump to content

Different banner in each category? With switch statement?


masif2024

Recommended Posts

plz help how to add 

Different banner in each category? With if statement 

i want to add banner at top of category page 

 

i have here example of  this kind and i also attached screen shots how i implment in prestashop in category.tpl file

 

switch($_GET['id'])
{
    case 1:
        $banner = '1.png';
       
    break;
 
    case 2:
        $banner = '2.png';
       
    break;
 
    case 3:
        $banner = '3.png';
        
  
    break;
  case 4:
        $banner = '4.png';
        
  
    break;
  case 5:
        $banner = '5.png';
        
  
    break;
}
$image = <<<EOF
<img src="$banner "/>
EOF;
 
echo $image;

post-1275059-0-13791500-1468999764_thumb.png

post-1275059-0-58461200-1468999765_thumb.png

post-1275059-0-23710100-1468999766_thumb.png

Link to comment
Share on other sites

 

plz help how to add 

Different banner in each category? With if statement 

i want to add banner at top of category page 

 

i have here example of  this kind and i also attached screen shots how i implment in prestashop in category.tpl file

 

switch($_GET['id'])
{
    case 1:
        $banner = '1.png';
       
    break;
 
    case 2:
        $banner = '2.png';
       
    break;
 
    case 3:
        $banner = '3.png';
        
  
    break;
  case 4:
        $banner = '4.png';
        
  
    break;
  case 5:
        $banner = '5.png';
        
  
    break;
}
$image = <<<EOF
<img src="$banner "/>
EOF;
 
echo $image;

 

Link to comment
Share on other sites

Try something like:

{if isset($smarty.get.id) && $smarty.get.id|intval >= 1 && $smarty.get.id|intval <= 5}
    <img src="{$img_dir}banners/{$smarty.get.id|intval}.png" width="1755" height="245" alt="" />
{/if}

Change the image width and height as required. You can then create a themes/<your_theme>/img/banners subdirectory and put the banners in there.

Link to comment
Share on other sites

 

 

plz help how to add 

Different banner in each category? With if statement 

i want to add banner at top of category page 

 

i have here example of  this kind and i also attached screen shots how i implment in prestashop in category.tpl file

 

switch($_GET['id'])
{
    case 1:
        $banner = '1.png';
       
    break;
 
    case 2:
        $banner = '2.png';
       
    break;
 
    case 3:
        $banner = '3.png';
        
  
    break;
  case 4:
        $banner = '4.png';
        
  
    break;
  case 5:
        $banner = '5.png';
        
  
    break;
}
$image = <<<EOF
<img src="$banner "/>
EOF;
 
echo $image;

 

 

 

the code you attached is a php code.

you cant use php in .tpl files, so in this case it will be much better to transform code to smarty and instead of switch - use if / elseif conditions

<img src="{if $smarty.get.id_cat==1}1.png{elseif $category->id==2}2.png{elseif $category->id==3}3.png{elseif $category->id==15}15.png{/if}"/>

with if condition you can handle much more id numbers, not only numbers between 1-5 as on example one reply above

Link to comment
Share on other sites

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...