Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sub-Category Banner


dreamingdesign

Recommended Posts

Hi,

 

I wanted to allocate an individual banner to each of the sub-category of my beauty products website.

 

I am not talking about the category image but a banner or advertising like image.

 

Please have a look at: http://www.stella-marketing.com/cetuem_01/

 

I am only starting with PHP, so I decided to get the Category Name variable in the index.php page and to use it as my image.

 

In the index.php page find:

 

<h1><?php echo $catname; ?></h1>

 

And add just bellow (or whenever you like this banner to be):

 

<?php

$catimagename = $catname . '';

$catimagename = strtolower($catimagename);

$catimagename = str_replace(" ", "_", $catimagename);

?>

 

<img src="images/<?php echo $catimagename; ?>.png">

 

The image you like to create need to have the same name as the category/sub-category.

 

If, for example, you need a picture on top of your Nail Enamels Collection category the name has to be nail_enamels_collection.png

 

You can create JPG or GIF or else picture format if you change the .png at the and of the last line.

You can change the _ in the picture name by - or else but to replace it with spaces might not be displayed in some system.

 

I hope it will help someone out there.

 

PS: Work in progess in my website. All picture will be uploaded by 12th of July 2011

 

Regards,

Stephane

post-294522-0-34074800-1310373238_thumb.jpg

Link to comment
Share on other sites

sweet simple solution !

 

if you want something more advanced, I have banner rotator from kymation and loaded banners for each category in groups reflecting the category path, so that the top level categories show a collection of banners from all the subcategories.

this setup allows for url links behind the banners, multi-language should you wish, and enable/disable for more flexibility.

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

This is my includes/modules/banner_rotator.php

 

There are a few changes to the standard file, but the thrick is at the top where a cPath switch is made.

futher I have a BANNER_ROTATOR_GROUP defined as 'C' and different group names named according to the cPath they apply to

so C1_11_21 would trigger the image to be displayed for category 21, 11 and 1

 

secondly the else switch finds matches in the categories directory (where I have these stored) based on the manufacturers name, this logic is purely based on image naming conventions, as it finds banners starting with the manufacturers name (with spaces replaced by underscores.

 

The module is included in index.php section where you want the banner to show up.

 

Hope this helps

Carine

<?php
/*
 $Id: banner_rotator.php 1.1 20100628 Kymation $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2010 osCommerce

 Released under the GNU General Public License
*/

if ($cPath <> '') {
 $where_clause = " banners_group like '" . BANNER_ROTATOR_GROUP . "$cPath%' ";
} else {
 $where_clause = " banners_image like 'categories/" . str_replace(" ", "_",strtolower($manresult['manufacturers_name'])). "%' ";
}
 $banner_query_raw = "
   select 
     banners_id,
     banners_url, 
     banners_image,
     banners_html_text
   from 
     " . TABLE_BANNERS . "
   where 
  $where_clause
  order by 
     " . BANNER_ORDER . " 
   limit 
     " . MAX_DISPLAY_BANNER_ROTATOR
 ;
// made it language independent
//      and language_id = '" . ( int )$languages_id . "'  
//
 //print $banner_query_raw; exit();
 $banner_query = tep_db_query( $banner_query_raw );
 //print tep_db_num_rows( $banner_query );exit();
 if( tep_db_num_rows( $banner_query ) > 1 ) {
?>
<!-- banner_rotator -->
 <div id="bannerRotator">
   <ul>
<?php 
   while( $banner = tep_db_fetch_array( $banner_query ) ) {

  //print_r($banner);exit();

  //preventief alle flash-animaties weglaten (anders worden ze in een img-tag gezet, hetgeen niet werkt)
  if(substr($banner['banners_image'], -3, 3) == 'swf')
    continue;

     echo '      <li>';
     if( $banner['banners_url'] != '' ) {
       echo '<a href="' . tep_href_link( FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">';
     }
     echo tep_image( DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_html_text'] );
     if( $banner['banners_url'] != '' ) {
       echo '</a>';
     }
     echo '</li>';

     tep_update_banner_display_count( $banner['banners_id'] );
   }
?>
   </ul>
   <div id="bannerNav"></div>
 </div>
 <div class="divider-tall"></div>
<!-- banner_rotator_EOF -->
<?php
 } elseif( tep_db_num_rows( $banner_query ) == 1 ) {
   $banner = tep_db_fetch_array( $banner_query );
 	//echo tep_display_banner('preview', $banner['banners_id']);
if (tep_not_null($banner['banners_html_text'])) {
     $banner_string = $banner['banners_html_text'];
   } else {
     if ( substr($banner['banners_image'], -3, 3) == 'swf' ) {
    $size = getimagesize(DIR_WS_IMAGES . $banner['banners_image']);
       if (tep_not_null($banner['banners_url'])) {
         $banner_string = '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_self">' . mm_output_flash_movie( $banner['banners_title'], DIR_WS_IMAGES . $banner['banners_image'] , $size[0]  , $size[1]) . '</a>';
       } else {
          $banner_string = mm_output_flash_movie( $banner['banners_title'], DIR_WS_IMAGES . $banner['banners_image'] , $size[0]  , $size[1]);
       }
} else {
       if (tep_not_null($banner['banners_url'])) {
         $banner_string = '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_self">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a>';
       } else {
         $banner_string = tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']);
       }
}
   }

   tep_update_banner_display_count($banner['banners_id']);

//next css classes enforce same layout as the rotator, but images doesn't flash, nor is there a navigation bar
?>
 <div id="bannerRotator">
   <ul>
<?php echo $banner_string;?>
   </ul>
 </div>
 <div class="divider-tall"></div>
<?php	
 }
?>

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

PS I also made the banner group field a bit larger with mysql, as I ran out of characters ...

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

  • 3 weeks later...

Hello dreamingdesign

 

How did you get the categories to appear in a table for example when you click on the heading for example Nail Care it reveals the sub categories

 

I want to do that on my site, I have got oscommerce 2.3.1 installed

 

Can you help me and let me know how you did it please

 

Thank you

 

Ian

Link to comment
Share on other sites

  • 5 months later...

You can also put this code on the index page,

 

 

<?php
if ($banner = tep_banner_exists('dynamic', (int)$current_category_id)) {
?><div id="index_banner">
 <?php echo tep_display_banner('static', $banner); ?>
</div><?php
 }
?>

 

In the admin banner manager you just need to create a group and call it the same as the category id. Eg: 11.

Link to comment
Share on other sites

  • 6 months later...

You can also put this code on the index page,

 

 

<?php
if ($banner = tep_banner_exists('dynamic', (int)$current_category_id)) {
?><div id="index_banner">
 <?php echo tep_display_banner('static', $banner); ?>
</div><?php
 }
?>

 

In the admin banner manager you just need to create a group and call it the same as the category id. Eg: 11.

 

Hi Mumme!

 

1st of all, this is a fabulous tip! It doesn't seem to be working for subcategories though (eg 31_3)...

Is there a way to get this to work for subcategories as well?

Link to comment
Share on other sites

$current_category_id is valid for every category, no matter what the level. Make sure your banner group is just the category ID number, not the cPath (e.g. 235 not 21_56_235).

 

Regards

Jim

See my profile for a list of my addons and ways to get support.

Link to comment
Share on other sites

have you tried just with "3" ?

it is based on the categories_id, not the full path.

KEEP CALM AND CARRY ON

I do not use the responsive bootstrap version since i coded my responsive version earlier, but i have bought every 28d of code package to support burts effort and keep this forum alive (albeit more like on life support).

So if you are still here ? What are you waiting for ?!

 

Find the most frequent unique errors to fix:

grep "PHP" php_error_log.txt | sed "s/^.* PHP/PHP/g" |grep "line" |sort | uniq -c | sort -r > counterrors.txt

Link to comment
Share on other sites

Hi guys, I tried just using the categories id, but that didn't work.

I decided to go with the categories description addon.

This way I add text and images to categories as well as subcategories ;)

Link to comment
Share on other sites

Try installing headertags_seo. This will help with many aspects of seo withing your site, and will allow you to add text to each category and subcategory, which also means that you can use html to add images.

REMEMBER BACKUP, BACKUP AND BACKUP

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...