supastoked Posted October 20, 2006 Posted October 20, 2006 Hi Guys, I wonder if anyone can help out with this.. I am trying to find a way that i can use a simple php conditional statement, to target the home page saying "if home page, show content A, else show content B" (ie the rest of the site).. The clients asked that the header graphic on her site should only show up on the home page, but since it resides in header.php i need to do some sort of conditional check.. Any suggestions whatsoever would be most appreciated! Regards, Chris
squeekit Posted October 20, 2006 Posted October 20, 2006 MAYBE TRY... if ( isset($HTTP_GET_VARS['cpath']) && tep_not_null($HTTP_GET_VARS['cpath']) { __ DO THE STUFF THAT'S ISN'T FOR HOMEPAGE __ } else { __ DO THE STUFF FOR HOMEPAGE __ )
supastoked Posted October 20, 2006 Author Posted October 20, 2006 Hi Squeekit, Thanks for the reply! I will give it a try and let you know how it works out ;0) Cheers, Chris
supastoked Posted October 20, 2006 Author Posted October 20, 2006 Hi Squeekit, I've tried two variations of your code, but neither seem to work :( I dont spose you can see if anything looks out of place, or have any other tricks up your sleeve? <td width=517 valign=top> <?php if ( isset($HTTP_GET_VARS['cpath']) && tep_not_null($HTTP_GET_VARS['cpath']) { ?> <?php } else { ?> <table cellspacing=0 cellpadding=0> <tr><td><img src=images/m20.jpg><img src=images/m21.jpg></td> <td width=120 align="right" valign="bottom"><img src="images/m22.jpg" /></td> </tr> </table> <?php ) ?> </td> second variation: <td width=517 valign=top> <?php if ( isset($HTTP_GET_VARS['cpath']) && tep_not_null($HTTP_GET_VARS['cpath']) { echo ' '; } else { echo '<table cellspacing=0 cellpadding=0> <tr><td><img src=images/m20.jpg><img src=images/m21.jpg></td> <td width=120 align="right" valign="bottom"><img src="images/m22.jpg" /></td> </tr> </table>'; ) ?> </td> thanks! chris
squeekit Posted October 20, 2006 Posted October 20, 2006 hmmm... try swapping if ( isset($HTTP_GET_VARS['cpath']) && tep_not_null($HTTP_GET_VARS['cpath']) { with if (isset($HTTP_GET_VARS['cPath'])) {
squeekit Posted October 20, 2006 Posted October 20, 2006 ohhh shoot - i bet the first fix works --- but it should be "cPath" and not "cpath" --- prolly case sensative ;) soooo... try: if ( isset($HTTP_GET_VARS['cPath']) && tep_not_null($HTTP_GET_VARS['cPath']) ) { sorry... :-"
squeekit Posted October 20, 2006 Posted October 20, 2006 also note the now new fix on the second ")" if ( isset($HTTP_GET_VARS['cPath']) && tep_not_null($HTTP_GET_VARS['cPath']) ) { sorry... :-" yup - should be good now...
supastoked Posted October 20, 2006 Author Posted October 20, 2006 I have to agree with you there - hmmmmm, it is!!! darn, i tried what you suggested - but still no joy!! I reckon the woman the header pic has decided she is there to stay and is playing silly buggers with the code!!! This is what i have in now.. <td width=517 valign=top> <?php if (isset($HTTP_GET_VARS['cPath'])) { ?> <?php } else { ?> <table cellspacing=0 cellpadding=0> <tr><td><img src=images/m20.jpg><img src=images/m21.jpg></td> <td width=120 align="right" valign="bottom"><img src="images/m22.jpg" /></td> </tr> </table> <?php } ?> Feel free to have a look (please excuse the site, i've only justed started cleaning up the mess i was given ;0) http://www.essencia.org.uk
supastoked Posted October 20, 2006 Author Posted October 20, 2006 Crikey squeekit, I was too slow there - missed ur reply!! Trying the new code now, holding thumbs ;0)
squeekit Posted October 20, 2006 Posted October 20, 2006 HEY THERE supastoked, after using if ( isset($HTTP_GET_VARS['cPath']) && tep_not_null($HTTP_GET_VARS['cPath']) ) { (what i think is good or should be good) DON"T FORGET TO HIT YOUR REFRESH BUTTON WHEN VIEWING PaGES AFTER THE EDIT..... else you might be viewing old versions from your cache
supastoked Posted October 20, 2006 Author Posted October 20, 2006 Hi Squeekit, I've tried ur suggestion as above, but its still displaying on all pages :(:( I've been clearing my cache, testing in different browsers and still no joy! Thats again for all your help on this - its very much appreciated!
squeekit Posted October 20, 2006 Posted October 20, 2006 i tested it here - works perfect - but i did notice at your site you are using SEO url's i was gonna play with that contrib next week... it must be something with the SEO contrib the site uses (the reason why it isn't workin for you)... let me know the IF statement that is present in your includes/application_top.php that is directly under the comment: // calculate category path (it's about 4/5 down that page) mine is thus: // calculate category path if (isset($HTTP_GET_VARS['cPath'])) { $cPath = $HTTP_GET_VARS['cPath']; } elseif (isset($HTTP_GET_VARS['products_id']) && !isset($HTTP_GET_VARS['manufacturers_id'])) { $cPath = tep_get_product_path($HTTP_GET_VARS['products_id']); } else { $cPath = ''; } AND AHHH SHOOT -- looks like the site is using a template system - meaning you might be editing the wrong file - hmmm
supastoked Posted October 20, 2006 Author Posted October 20, 2006 Strange, mine seems to be the same.. // calculate category path if (isset($HTTP_GET_VARS['cPath'])) { $cPath = $HTTP_GET_VARS['cPath']; } elseif (isset($HTTP_GET_VARS['products_id']) && !isset($HTTP_GET_VARS['manufacturers_id'])) { $cPath = tep_get_product_path($HTTP_GET_VARS['products_id']); } else { $cPath = ''; }
squeekit Posted October 20, 2006 Posted October 20, 2006 lol - sorry for the run around - but i'm only here ten more minutes... sooo.... if you could answer 3 Q's fast then perhaps try the code provided below.... 1 - in includes/classes/navigation_history.php does your function add_current_page (near top) look like this? ..............EDIT................ function add_current_page() { global $PHP_SELF, $HTTP_GET_VARS, $HTTP_POST_VARS, $request_type, $cPath; $set = 'true'; for ($i=0, $n=sizeof($this->path); $i<$n; $i++) { if ( ($this->path[$i]['page'] == basename($PHP_SELF)) ) { if (isset($cPath)) { if (!isset($this->path[$i]['get']['cPath'])) { continue; } else { ..............EDIT................ 2 - does the top of your product_info.php look like this? <?php /* $Id: product_info.php,v 1.97 2003/07/01 14:34:54 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ require('includes/application_top.php'); require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO); $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product_check = tep_db_fetch_array($product_check_query); ?> ............EDIT............ 3 - are you sure you are editing the file that matters -- could the site be using a template where the file used to display is actually "duplicated" somewhere else? ------------------------------------------ code to try --- tested here 100% - basically it is a shorthand IF for what you've tried already <?php echo ( ( isset($HTTP_GET_VARS['cPath']) && tep_not_null($HTTP_GET_VARS['cPath']) ) ? ' ' : '<table cellspacing="0" cellpadding="0"> <tr> <td><img src="images/m20.jpg" /><img src="images/m21.jpg" /><img src="images/m22.jpg" /></td> </tr> </table>'); ?> try to answer Q's before trying code...
supastoked Posted October 20, 2006 Author Posted October 20, 2006 navigation_history.php: function add_current_page() { global $PHP_SELF, $HTTP_GET_VARS, $HTTP_POST_VARS, $request_type, $cPath; $set = 'true'; for ($i=0, $n=sizeof($this->path); $i<$n; $i++) { if ( ($this->path[$i]['page'] == basename($PHP_SELF)) ) { if (isset($cPath)) { if (!isset($this->path[$i]['get']['cPath'])) { continue; } else { if ($this->path[$i]['get']['cPath'] == $cPath) { array_splice($this->path, ($i+1)); $set = 'false'; break; } else { $old_cPath = explode('_', $this->path[$i]['get']['cPath']); $new_cPath = explode('_', $cPath); for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) { if ($old_cPath[$j] != $new_cPath[$j]) { array_splice($this->path, ($i)); $set = 'true'; break 2; } } } } } else {
supastoked Posted October 20, 2006 Author Posted October 20, 2006 product_info.php: <?php /* $Id: product_info.php,v 1.97 2003/07/01 14:34:54 hpdl Exp $ osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ require('includes/application_top.php'); require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO); $product_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'"); $product_check = tep_db_fetch_array($product_check_query); ?>
supastoked Posted October 20, 2006 Author Posted October 20, 2006 i've been editing the header.php and i cant see how it could have a duplicate entry somewhere else, since the headers included into the index.php... :(
supastoked Posted October 20, 2006 Author Posted October 20, 2006 Just tried the shorthand and no luck either :( Thanks for your help Squeekit! I'll keep trying and hopefully someone else will have some more input as to what i am doing wrong :)
♥Monika in Germany Posted October 20, 2006 Posted October 20, 2006 Hi Guys,I wonder if anyone can help out with this.. I am trying to find a way that i can use a simple php conditional statement, to target the home page saying "if home page, show content A, else show content B" (ie the rest of the site).. The clients asked that the header graphic on her site should only show up on the home page, but since it resides in header.php i need to do some sort of conditional check.. Any suggestions whatsoever would be most appreciated! Regards, Chris I use: if ((basename($PHP_SELF) == FILENAME_DEFAULT && $cPath == '')) { //do stuff for homepage } else { //do stuff for other pages } :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...
squeekit Posted October 20, 2006 Posted October 20, 2006 mmm sorry to let you down - but if the A to Q 3 doesn't turn anything up for you, then i'm at a loss... it seems that even though the site is using non-default SEO url's that the urls are still being handled in the default manner (as indicated by the samples of the files you provided) - and so i would think the "default" solution i provided would work... and so the only conclusion i am left with is perhaps you are using a template system where you'll have apply the edit to a different file (perhaps - a big "perhaps") - maybe i'm just missing something - i'll prolly be slammin myself next week > "i'm so stupid - i'm so stupid" lol i can only squeek out one more idea at this time (super long shot) maybe there is some kinda "wrapper" for those SEO url's - meaning maybe somehow that the files that are yet using the default method of dealing with the default url's have access to some sort of SEO url translator -- but i doubt it - by next week i'll know... :blush: i'll know by next week --- hopefully someone who knows now can give you a hand last idea.... get rid of the added tep_not_null($HTTP_GET_VARS['cPath']) condition -- your SEO links are not default in that they do not appear like this > "cPath=21" - sooo - maybe they are always null with SEO (???) --- but even if it works like so - be sure to test, test, test (click, click click = nav all 'round the site) <?php echo ( isset($HTTP_GET_VARS['cPath']) ? ' ' : '<table cellspacing="0" cellpadding="0"> <tr> <td><img src="images/m20.jpg" /><img src="images/m21.jpg" /><img src="images/m22.jpg" /></td> </tr> </table>'); ?> i'll stop in later - see how ya made out - good luck --- cool - you gots more help ;) oooo - looks good too
squeekit Posted October 20, 2006 Posted October 20, 2006 hi Monika in Germany, is / was the SEO url's the reason my "refined" code worked 100% for me but not for supastoked site?
♥Monika in Germany Posted October 20, 2006 Posted October 20, 2006 sorry, did not check that code (which posting #?). I just copied in my own that I use on SEO URL and non SEO sites equally. :-) Monika addicted to writing code ... can't get enough of databases either, LOL! my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum Interactive Media Award July 2007 ~ category E-Commerce my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...
squeekit Posted October 20, 2006 Posted October 20, 2006 i was stuck on getting location with HTTP_GET_VARS <?php echo ( ( isset($HTTP_GET_VARS['cPath']) && tep_not_null($HTTP_GET_VARS['cPath']) ) ? '___do stuff for other pages___' : '___do stuff for homepage___'); ?> i'm thinking this is what made it not work with SEO URL's: tep_not_null($HTTP_GET_VARS['cPath'])
Recommended Posts
Archived
This topic is now archived and is closed to further replies.