WordPress PHP If else help

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..

Related posts

Leave a Reply

4 comments

  1. 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
    }
    
  2. 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 } ?>