Reputation: 1343
I tried doing this but then it is not working
<?php
if ($_SERVER['SERVER_NAME']=='http://www.testground.idghosting.com/idi' && $_SERVER['REQUEST_URI'] == 'our-production/') {
echo '<div id="services">
<h1>Our services</h1>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_productions" title="Our Productions"><span>Our Productions</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_services" title="Production Services"><span>Production Services</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_equipment" title="Equipment & Facilities"><span>Equipment & Facilities</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_pr" title="PR & Media"><span>PR & Media</span></a>
</div>';
} else {
echo '<div> do not show</div>';
} ;
?>
to see the sample click here see the block where it says Our services in the bottom I don't want it to be shown on ths page but visible to all other pages....
Upvotes: 0
Views: 9861
Reputation:
try this and it is working for me ...
$data['test']=basename($_SERVER['REQUEST_URI'], '?' . $_SERVER['QUERY_STRING']);
if($data['test'] == 'our-production')
{
echo '<div id="services">
<h1>Our services</h1>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_productions" title="Our Productions"><span>Our Productions</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_services" title="Production Services"><span>Production Services</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_equipment" title="Equipment & Facilities"><span>Equipment & Facilities</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_pr" title="PR & Media"><span>PR & Media</span></a>
</div>';
} else {
echo '<div> do not show</div>';
} ;
}
Upvotes: 0
Reputation: 12276
The problem here is that in the echo string, you open a php tag, but that is already php code, so you don't have to open that tag. You'd have to one one if you were in HTML code.
Upvotes: 0
Reputation: 655319
You’re using the wrong values.
// REQUEST_URI is the requested URI path plus the requested URI query, so let’s strip the latter
$_SERVER['REQUEST_URI_PATH'] = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
// HTTP_HOST may not be set if the request didn’t contain the Host header field (just HTTP/1.0)
if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']=='www.testground.idghosting.com' && $_SERVER['REQUEST_URI_PATH'] == '/idi/our-production/') {
// host is "www.testground.idghosting.com" and requested URI path is "/idi/our-production/"
}
See the manual for what values the $_SERVER
contains.
Upvotes: 2
Reputation: 6122
At a higher level, have you considered changing your approach for getting this onto the pages where you want it? You could put the section within the then part of your code into a separate file which you include into those files in which you want it to appear.
Upvotes: 0
Reputation: 8481
Always indent your code — it's simplier to see errors
<?php
if ($url == "http://www.sample.com/test.php") {
echo "<div>whatever</div>";
} else {
echo "<div> do not show</div>";
};
?>
Note the placement of curly brackets.
Upvotes: 10
Reputation: 268364
Or you could use the ternary operator. All on one line if you like - I broke it up to avoid the evil scrollbars.
echo ($url == "http://www.sample.com/test.php")
? "<div>Whatever</div>"
: "";
Upvotes: 3
Reputation: 9925
There does not currently seem to be a direct way. What you’ll have to do is to reconstruct the URL by combining entries from the $_SERVER array. You can check the results of the phpinfo() to see what entries you need.
Upvotes: 0
Reputation: 30133
<?php
if ($_SERVER['SERVER_NAME']=='www.sample.com' && $_SERVER['REQUEST_URI'] == '/test.php') {
echo 'blah';
} else {
echo 'asdf';
}
?>
Upvotes: 2
Reputation: 143
<?php
if($url == "http://www.sample.com/test.php")
{
echo "<div>whatever</div>";
}
else
{
echo "<div> do not show</div>";
}
?>
Your syntax was just a little wrong.
Upvotes: 0