Page 1 of 1

URL Comparison If statement

Posted: Wed Sep 17, 2008 11:57 am
by bcyork
I know very little about PHP but i have tried reasearched 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.

Re: URL Comparison If statement

Posted: Thu Nov 13, 2008 3:26 am
by novice4eva

Code: Select all

 
<?php 
$curPageURL = curPageURL();
if($curPageURL == "http://www.DOMAIN.com") { 
include (TEMPLATEPATH . '/featured.php'); 
 } 
?>
 
Is it me or your code is self contradictory! Since the <div id="feaured"> is contained in the featured.php how can you block it when url equals http://www.DOMAIN.com WHEN in the previous part you have included featured.php only when the url equals http://www.DOMAIN.com. :crazy:

Just omit that DIV, it seems like you don't need it at all. Please explain it well. Now at the start of your post, it makes sense a bit, it implies that you would avoid the div when there is certain get parameter involved, that can be achieved inside the featured.php
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.
by simply checking the get parameter.