1

I have been trying this for hours

<?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 &amp; Facilities"><span>Equipment &amp; Facilities</span></a>
<a href="<?php bloginfo(\'url\'); ?>" id="serv_pr" title="PR &amp; Media"><span>PR &amp; Media</span></a>

</div>';
     } else {
         echo '<div> do not show</div>';
     } ;
 ?>

but no luck... a help would be very much appreciated..

4 Answers 4

5

That's never going to match because $_SERVER['SERVER_NAME'] is just the domain name of the server, not the url itself.

Some of the items in the $_SERVER array that may be of use to you:

  • SERVER_NAME The full domain name of the server executing the script (eg myserver.foo.com)
  • REQUEST_URI The portion of the URL that comes after the server name, including the query string (if any)
  • SCRIPT_NAME The portion of the URL after the server name, excluding the query string.

One thing I like to do for handling code that gets executed for development and not on a live site is to create a define based on the hostname.

For example:

define('IS_LIVE', (strstr($_SERVER['SERVER_NAME'], 'mytestserver') ? true : false));

If I put that define somewhere that gets called for every page, then elsewhere in my code, I can do this:

if(!IS_LIVE) {
  //Do development-debugging stuff
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the ups I didt the print_r($_SERVER); command and copied the server, request_uri but still not working
Are you trying to make it so the if statement only runs on www.testground.idghosting.com?
0

You also have an extra semi-colon:

</div>';
  } else {
      echo '<div> do not show</div>';
  } ; 
//  ^ remove this semi-colon

1 Comment

I dont think this will give a syntax error in php. Its just an empty statement.
0

Use

if(substr($_SERVER["REQUEST_URI"], 0, 4) == "/idi" //followed by your other code

Comments

-1

I have the solution....

<?php
//use body ID to whick page you want to dipaly a block
if (is_page(array('bodyid','bodyid', 'bodyid'))) { ;?>

<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 &amp; Facilities"><span>Equipment &amp; Facilities</span></a>
<a href="<?php bloginfo('url'); ?>" id="serv_pr" title="PR &amp; Media"><span>PR &amp; Media</span></a>

</div>
<?php } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.