Jump to content



Photo
- - - - -

Sub-Category Banner


This topic has been archived. This means that you cannot reply to this topic.
12 replies to this topic

#1   dreamingdesign

dreamingdesign
  • Members
  • 1 posts

Posted 11 July 2011 - 08:34

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

Attached Files



#2 ONLINE   bruyndoncx

bruyndoncx

    osCommerce Teenager

  • Members
  • 3,067 posts

Posted 11 July 2011 - 12:13

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.
Don't just sit there - contribute to the responsive bootstrap community effort !
http://forums.oscomm...iew__getnewpost


Hava a nice day !
Carine Bruyndoncx


Seen anything good relevant on the net about responsive design for ecommerce ?
You might as well post it in my responsive liive shop review thread .

#3   wendy_purple

wendy_purple
  • Members
  • 12 posts

Posted 13 July 2011 - 00:18

Hi Carine, I'm interested in the banner rotator for each category.
Please tell me more about this.
Thanks in advance

#4 ONLINE   bruyndoncx

bruyndoncx

    osCommerce Teenager

  • Members
  • 3,067 posts

Posted 13 July 2011 - 21:47

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	
  }
?>

Don't just sit there - contribute to the responsive bootstrap community effort !
http://forums.oscomm...iew__getnewpost


Hava a nice day !
Carine Bruyndoncx


Seen anything good relevant on the net about responsive design for ecommerce ?
You might as well post it in my responsive liive shop review thread .

#5 ONLINE   bruyndoncx

bruyndoncx

    osCommerce Teenager

  • Members
  • 3,067 posts

Posted 13 July 2011 - 21:48

PS I also made the banner group field a bit larger with mysql, as I ran out of characters ...
Don't just sit there - contribute to the responsive bootstrap community effort !
http://forums.oscomm...iew__getnewpost


Hava a nice day !
Carine Bruyndoncx


Seen anything good relevant on the net about responsive design for ecommerce ?
You might as well post it in my responsive liive shop review thread .

#6   ianhaney

ianhaney
  • Members
  • 859 posts

Posted 30 July 2011 - 14:01

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

#7   mumme

mumme
  • Validating
  • 121 posts

Posted 05 January 2012 - 13:52

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.

#8   JSR

JSR
  • Members
  • 149 posts

Posted 24 July 2012 - 16:31

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?

#9   kymation

kymation

    Code Monkey

  • Community Sponsor
  • 8,027 posts

Posted 24 July 2012 - 18:03

$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

My Addons

Banners Box Download Support
Categories Accordion Box Download Support
Closest Shipper 2.2x Support
Document Manager 2.2x Support
Generic Box Download Support
Get 1 Free 2.2x Support
Price in Cart Only/MAPP Download Support
Modular Front Page Download Support
Modular SEO Header Tags Download Support
MVS 2.2x Support
PDF Datasheet Download Support
Price Updater 2.2x
Products Specifications 2.3.x Development Version Support Bugs/Suggestions
Request a Review Download Support

Shopping List Download Support New!
Specials Image Overlay Download Support
Superfish Categories Box Download Support
Theme Switcher 2.3+ Support  Updated


#10 ONLINE   bruyndoncx

bruyndoncx

    osCommerce Teenager

  • Members
  • 3,067 posts

Posted 24 July 2012 - 18:03

have you tried just with "3" ?
it is based on the categories_id, not the full path.
Don't just sit there - contribute to the responsive bootstrap community effort !
http://forums.oscomm...iew__getnewpost


Hava a nice day !
Carine Bruyndoncx


Seen anything good relevant on the net about responsive design for ecommerce ?
You might as well post it in my responsive liive shop review thread .

#11   JSR

JSR
  • Members
  • 149 posts

Posted 26 July 2012 - 13:21

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 /wink.png' class='bbc_emoticon' alt=';)' />

#12   14steve14

14steve14
  • Members
  • 3,506 posts

Posted 26 July 2012 - 15:16

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

Don't take life too seriously. no one gets out alive anyway

#13   JSR

JSR
  • Members
  • 149 posts

Posted 04 August 2012 - 20:56

Thanks for the tip Steve! I allready have SEO URLS 5 installed though...