About Club osCommerce

Showcasing osCommerce - the good, the bad and the ugly!

StumbleUpon It! DIGG It!

Header Images Per Category (again!)

Written By Gary on Aug 28 2008 ·

Ryan says;

I want to have header images display per category, how can I do this. I already have made a script buts its really repetitive.

The code Ryan had come up with was really quite complicated, repetitive and pointless. My idea is like this:

PHP:
  1. <?php
  2. switch ($current_category_id) {
  3.    case 41:
  4.    echo tep_image(DIR_WS_IMAGES . '13g_banner.jpg', '');
  5.    break
  6.    case 42:
  7.    echo tep_image(DIR_WS_IMAGES . 'mainad.jpg', 'Radioactive');
  8.    break
  9.    default:
  10.    echo tep_image(DIR_WS_IMAGES . 'MyDefaultHeader.jpg', 'Standard Header Alt Text');
  11. }
  12. ?>

We know that the function called tep_image is used to pick out an image grab the alt text and display it, so we can use this along with the switch (based on current_category_id) to show the relevant image.

The current_category_id is used in FILENAME_DEFAULT (usually index.php) and shows the category ID of the category you are currently in - surprising that it is called current_category_id wouldn't you say ;)

The above code is off the top of my head and is actually untested, so if anyone does try it and it goes wrong, let me know and I'll amend this post.

For reference, see http://uk.php.net/switch for more details on switching.


Buy Gary A Beer?
Buying me a "beer" helps me to keep my contributions updated and keep this blog alive. Cheers!


No Comments

No comments yet.

Leave a comment

RSS feed for comments on this post · TrackBack URL

Hot 100 osCommerce Shops

View the osCommerce HOT 100These are the best looking, most exceptional osCommerce Stores as voted for by you.

New to osCommerce - get inspiration from these beautiful shops. Reckon your site has what it takes to become a member of the HOT 100? Submit it!