yubnub Posted April 13, 2008 Posted April 13, 2008 Hi, I would like to set my site so that the site logo changes depending on what category is being viewed. I am thinking that by using some form of IF and ELSE script i could display a more relevent themed logo/image depending on the category being viewed. I assume this is possable, just wondered if any has either done it before or if anyone can offer any pointers as to where the best place to put such code would be. Many thanks for any help people can give, anthony
germ Posted April 13, 2008 Posted April 13, 2008 This is one way. In your /catalog/includes/header.php, find this code: <td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce') . '</a>'; ?></td> You'll probably have a different image name there because it's your logo, but I think you'll know which line I mean. Alter the code to something like this: <?php switch ( $cPath ) { case '1' : $show_me = 'image_1.gif'; break; case '2' : $show_me = 'image_2.gif'; break; default: $show_me = 'oscommerce.gif'; } ?> <td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . $show_me, 'osCommerce') . '</a>'; ?></td> Of course, you'll need to alter the image names and the values for $cPath to suit your needs. And you can add as many 'case' statements as you want. I only have two, but you can add more. As always, it's a good idea to backup any file before making any edits. There may be other ways to do this, and some might 'chime in' and say it's better to use a different variable other than $cPath. I say it's hard to argue with success - This works (I tested the code). :P If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 13, 2008 Author Posted April 13, 2008 Many thanks, Funnily enough I modded that code just yesterday when I upgraded from header tags to header tags seo! so I know exactly where to find it. Do i just add my category number after $cpath and upload the relevant images? Can I use the use the same code for other images I have in my column_left and right? thanks for your help This is one way. In your /catalog/includes/header.php, find this code: <td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . 'oscommerce.gif', 'osCommerce') . '</a>'; ?></td> You'll probably have a different image name there because it's your logo, but I think you'll know which line I mean. Alter the code to something like this: <?php switch ( $cPath ) { case '1' : $show_me = 'image_1.gif'; break; case '2' : $show_me = 'image_2.gif'; break; default: $show_me = 'oscommerce.gif'; } ?> <td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . $show_me, 'osCommerce') . '</a>'; ?></td> Of course, you'll need to alter the image names and the values for $cPath to suit your needs. And you can add as many 'case' statements as you want. I only have two, but you can add more. As always, it's a good idea to backup any file before making any edits. There may be other ways to do this, and some might 'chime in' and say it's better to use a different variable other than $cPath. I say it's hard to argue with success - This works (I tested the code). :P
germ Posted April 13, 2008 Posted April 13, 2008 Just alter the number after the "case" and the image names in the lines like this: case '1' : $show_me = 'image_1.gif'; Whatever your category is, is the number to put there. And put your default site logo here: default: $show_me = 'oscommerce.gif'; If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 14, 2008 Author Posted April 14, 2008 Hi again, I cant seem to get it working, i must be doing something wrong, this is what i have done ( i ahve tried it with 1 and 2 cases Thanks again <?php switch ( $cPath=27 ) { case '1' : $show_me = 'swim_equip1.jpg'; break; default: $show_me = 'swim_equip.jpg'; } ?> <td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . $show_me, 'swim_equip') . '</a>'; ?>
germ Posted April 14, 2008 Posted April 14, 2008 <?php switch ( $cPath ) { case '27' : $show_me = 'swim_equip1.jpg'; break; default: $show_me = 'swim_equip.jpg'; } ?> Clearer now? :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
germ Posted April 14, 2008 Posted April 14, 2008 :thumbsup: The "down" side of this is that each time you add a category you want to associate a new header image with, you have to edit your source code. Maybe there's a contribution that does the same thing in a "better" fashion, I haven't looked. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 14, 2008 Author Posted April 14, 2008 I dont mind editing the code each time, I am not going o use it on many categorys. I suppose it would be nice to be able to control it all from the admin, perhaps somebody will put the code together one day. I think your code works just fine. Is it possable to mod the code slightly so you could use it to display an image if the relevent catagory is being viewed but display no image if not? anthony
germ Posted April 14, 2008 Posted April 14, 2008 Yes it's possible. But do you really want a header with no image at all sometimes (if I understand what you mean)? :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 14, 2008 Author Posted April 14, 2008 I was thinking of using the code on other images as well. I put the odd "advert" image in my column left and right to "balance" the page. This code would allow me to a) target the adverts to relevent categorys B) choose when and when o not display adverts
germ Posted April 14, 2008 Posted April 14, 2008 OIC ;) If you want no image at all to display unless a category with an alternate header image is being viewed, change this line of code: default: $show_me = ''; And you need to change this code: <td valign="middle"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . $show_me, 'swim_equip') . '</a>'; ?> To: <?php if ( tep_not_null($show_me) ) { ?> <tr><td> <?php echo tep_image(DIR_WS_IMAGES . $show_me, 'swim_equip'); ?> </td></tr> <?php } ?> to show an image in column_left or right. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
germ Posted April 14, 2008 Posted April 14, 2008 Since I changed my original post, I'll post again just to be sure you know I made a change. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 14, 2008 Author Posted April 14, 2008 All works a charm. I am now also using the code for the image at the bottom of my column left.php Many thanks jim for all your help tonight, I hope this code being posted on here helps someboy else in the future. best regards, anthony
germ Posted April 14, 2008 Posted April 14, 2008 Because you introduced a new situation, here's a code update if using for column_left or right: <?php switch ( $cPath ) { case '1' : $show_me = 'image_1.gif'; $alt_txt = 'Text for mouseover'; break; case '2' : $show_me = 'image_2.gif'; $alt_txt = 'Text for mouseover'; break; default: $show_me = ''; } if ( tep_not_null($show_me) ) { echo '<tr><td>' . tep_image(DIR_WS_IMAGES . $show_me, $alt_txt) . '</td></tr>' . "\n"; } ?> The second parameter in tep_image is the text to display on a mouseover. This code lets you specify that. I didn't think it was necessary in the header 'cuz you just want the store name there. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 15, 2008 Author Posted April 15, 2008 Because you introduced a new situation, here's a code update if using for column_left or right: <?php switch ( $cPath ) { case '1' : $show_me = 'image_1.gif'; $alt_txt = 'Text for mouseover'; break; case '2' : $show_me = 'image_2.gif'; $alt_txt = 'Text for mouseover'; break; default: $show_me = ''; } if ( tep_not_null($show_me) ) { echo '<tr><td>' . tep_image(DIR_WS_IMAGES . $show_me, $alt_txt) . '</td></tr>' . "\n"; } ?> The second parameter in tep_image is the text to display on a mouseover. This code lets you specify that. I didn't think it was necessary in the header 'cuz you just want the store name there.
yubnub Posted April 15, 2008 Author Posted April 15, 2008 hi Jim, Sorry have been away for a day or so. Many thanks for the update, that code fixes one problem of all the same "advert" images having to have the same alt text. On the same lines , could the code be so each image has a diferent link? thanks anthony
germ Posted April 15, 2008 Posted April 15, 2008 Sure. What do you want them to link to? :unsure: If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 15, 2008 Author Posted April 15, 2008 Hi either a product you sell or perhaps a new category you have just added, could the code be simular to the code you just posted for the alt text eg case '1' : $show_me = 'image_1.gif'; $alt_txt = 'Text for mouseover'; $link '----insertlink here--------' break; Hope that makes sense Sure. What do you want them to link to? :unsure:
yubnub Posted April 15, 2008 Author Posted April 15, 2008 Think i have sussed it, is this correct?? <?php switch ( $cPath ) { case '33' : $show_me = 'atomic_cl.jpg'; $alt_txt = 'Text for mouseover'; $link = 'atomic-frameless-mask-p-341.html'; break; case '33_78' : $show_me = 'atomic_cl.jpg'; $alt_txt = 'Text for mouseover'; $link = 'atomic-frameless-mask-p-341.html'; break; default: $show_me = 'gekkofp.jpg'; $link = 'underwater-cameras-c-83.html'; $alt_txt = 'Text for mouseover'; } ?> <td valign="middle" style="padding-top:5px; "><p><?php echo '<a href="' . tep_href_link($link) . '">' . tep_image(DIR_WS_IMAGES . $show_me, $alt_txt, '') . '</a>'; ?></td> It seems to work? thanks again anthony
germ Posted April 16, 2008 Posted April 16, 2008 I was just getting ready to post something else, but it wouldn't work with SEF URL's (I don't think). I say if your code works - run with it! :) The rest of the code here would be for anyone wanting to try this that isn't using SEF URL's. Make a backup of what you have in case I don't have it quite right (as I haven't tested this code). <?php switch ( $cPath ) { case '1' : $show_me = 'image_1.gif'; $alt_txt = 'Text for mouseover'; $cat_id = ''; /* category link - this field MUST be filled out */ $prod_id = ''; /* product link - this field ONLY to be filled out when linking to a product */ break; case '2' : $show_me = 'image_2.gif'; $alt_txt = 'Text for mouseover'; $cat_id = ''; /* category link - this field MUST be filled out */ $prod_id = ''; /* product link - this field ONLY to be filled out when linking to a product */ break; default: $show_me = ''; } if ( tep_not_null($show_me) ) { $link_string = '<a href="'; $cPath_new = 'cPath=' . $cat_id; if ( tep_not_null($prod_id) ) { $cPath_new .= '&products_id=' . $prod_id; $link_string .= tep_href_link(FILENAME_PRODUCT_INFO, $cPath_new) . '">'; } else { $link_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; } $link_string .= tep_image(DIR_WS_IMAGES . $show_me, $alt_txt) . '</a>'; echo '<tr><td>' . $link_string . '</td></tr>' . "\n"; } ?> This new code has two new fields. $cat_id = ''; /* category link - this field MUST be filled out */ $prod_id = ''; /* product link - this field ONLY to be filled out when linking to a product */ The first ( $cat_id ) must always have a value between the tick marks. Only fill out the second ( $prod_id ) when linking to a particular product. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 16, 2008 Author Posted April 16, 2008 if you wish to have a link on ht e default image would the alt text and link for the default image need to be added below default: $show_me = ''; ie default: $show_me = ''; $alt_txt = 'Text for mouseover'; $cat_id = ''; /* category link - this field MUST be filled out */ $prod_id = ''; /* product link - this field ONLY to be filled out when linking to a product */ thanks
germ Posted April 16, 2008 Posted April 16, 2008 default: $show_me = ''; If that's true, it won't display any link at all. If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you. "Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice." - Me - "Headers already sent" - The definitive help "Cannot redeclare ..." - How to find/fix it SSL Implementation Help Like this post? "Like" it again over there >
yubnub Posted April 16, 2008 Author Posted April 16, 2008 <?php switch ( $cPath ) { case '33' : $show_me = 'atomic_cl.jpg'; $alt_txt = 'Atomic Aquatics Frameless Mask only £52.99'; $cat_id = '33'; /* category link - this field MUST be filled out */ $prod_id = ''; /* product link - this field ONLY to be filled out when linking to a product */ break; default: $show_me = 'gekkofp.jpg'; $alt_txt = 'Digital Underwater Camera Packages from only £164.99'; $cat_id = '83'; /* category link - this field MUST be filled out */ $prod_id = ''; /* product link - this field ONLY to be filled out when linking to a product */ } if ( tep_not_null($show_me) ) { $link_string = '<a href="'; $cPath_new = 'cPath=' . $cat_id; if ( tep_not_null($prod_id) ) { $cPath_new .= '&products_id=' . $prod_id; $link_string .= tep_href_link(FILENAME_PRODUCT_INFO, $cPath_new) . '">'; } else { $link_string .= tep_href_link(FILENAME_DEFAULT, $cPath_new) . '">'; } $link_string .= tep_image(DIR_WS_IMAGES . $show_me, $alt_txt) . '</a>'; echo '<tr><td>' . $link_string . '</td></tr>' . "\n"; } ?> Thanks for your onging help with this code
desiredin Posted April 16, 2008 Posted April 16, 2008 Jim, I love the code you initially gave the other day, and now I want to further modify it if possible. I would like to have the header image change if on specific pages. Is that possible? If you look how I have implemented it here: http://www.visceralmagic.com you will see I have "Category Image" text which is a transparent png for the background to show through. It will change to category names for the specific categories being viewed. I would like it to change for instance, to "Reviews" when my customer is in the review related pages, or My Account, in account related sections, Shopping Cart, when view shopping cart, etc.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.