bcyork Posted September 17, 2008 Share Posted September 17, 2008 I know a little about PHP but i have tried, researched and tried and can't get this to work any help would be appreciated. This is for a wordpress theme. What i want to do is to take the index.php file and remove a portion of it if the URL is different than http://www.DOMAIN.com. So if is http://www.DOMAIN.com/?cat=3 then it would not show this featured section. <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <div id="main" class="fix"><a name="main"></a> <?php if($curPageURL == "http://www.DOMAIN.com") { ?> <?php include (TEMPLATEPATH . '/featured.php'); ?> <?php } ?> <div id="content"> ... The getting URL part above works perfectly and has been tested with the echo function. But i can't seem to get the loop to work as simple as this should be. I have tried everyway i can find on the net and apparently i'm missing something. But as of just now i realized that I need a curve ball in it for it to actually work. The if then statement should read like this {If URL=www.domain.com THEN <?php include (TEMPLATEPATH . '/featured.php'); ?> ELSE <div id="featured"><h3 class="mainblock">Featured Stories</h3></div> } <div id="content"> Those two lines should never be executed on the same page because the second line with div id="feaured" is contained in the featured.php. I know this is probably stupid simple but i have tried. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/ Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 What loop are you referring to? Also, if statements should look like this: <?php if (condition){ code to execute; } else{ other code to execute; } ?> Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/#findComment-644308 Share on other sites More sharing options...
bcyork Posted September 18, 2008 Author Share Posted September 18, 2008 Here is sort of what i need but its messing up the page and the if statement isn't working. Sperately the parts on the inside of the if statement work fine but not as they are here. And again the get URL part works. <?php get_header(); ?> <div id="mid" class="fix"> <div id="main" class="fix"><a name="main"></a> <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <div id="main" class="fix"><a name="main"> <?php if ($curPageURL == "http://www.DOMAIN.com/"){ include (TEMPLATEPATH . '/featured.php'); } else{ ?> <div id="featured"> <h3 class="mainblock">Featured Stories</h3></div> <?php } ?> <div id="content"> Here is the portion of the original code <?php get_header(); ?> <div id="mid" class="fix"> <div id="main" class="fix"><a name="main"></a> <?php include (TEMPLATEPATH . '/featured.php'); ?> <div id="content"> Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/#findComment-644436 Share on other sites More sharing options...
bcyork Posted September 18, 2008 Author Share Posted September 18, 2008 Ohh and if it helps this is from the Massive News wordpress theme index.php file http://www.wpelements.com/2008/01/15/introducing-the-massive-news-wordpress-theme/ Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/#findComment-644439 Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 Try changing this line: if ($curPageURL == "http://www.DOMAIN.com/"){ to this: if ($curPageURL() == "http://www.DOMAIN.com/"){ Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/#findComment-644442 Share on other sites More sharing options...
bcyork Posted September 18, 2008 Author Share Posted September 18, 2008 This worked. With the () but with out the $ if (curPageURL() == "http://www.DOMAIN.com/"){ Although the formatting is still messed up. Is their anything there that should mess up page formating/layout? Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/#findComment-644485 Share on other sites More sharing options...
bcyork Posted September 18, 2008 Author Share Posted September 18, 2008 I fixed it there was a repeated div & id tag .. noticed it when i was cleaning up the code. Thank You so much. Link to comment https://forums.phpfreaks.com/topic/124736-url-comparison/#findComment-644490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.