WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $_SERVER[’SCRIPT_NAME’ issues (3 posts)

  1. neilscott
    Member
    Posted 7 years ago #

    Hello,

    I am trying to combine dynamic menus (described so well in the codex) with another level of functionality that involves specifying a different php file for each top level page (which contain the subpages). Sounds complicated, well here's an example of how it should look: http://www.bipcorporate.com

    What I don't seem to be able to work out is how to specify a specific php rule. This is what I've worked out so far:

    <?php
    if ($_SERVER[’SCRIPT_NAME’]='/about') {
    include( TEMPLATEPATH . '/nav/about.php');
    }
    elseif ($_SERVER[’SCRIPT_NAME’]='/contact') {
    include( TEMPLATEPATH . '/nav/contact.php');
    }
    else {
    include( TEMPLATEPATH . '/nav/home.php');
    }
    ?>

    But it doesn't work.

    Any ideas?

    Thanks,

    Neil

  2. Dion Hulse
    WordPress Dev
    Posted 7 years ago #

    i'd try using $_SERVER["REQUEST_URI"] instead of $_SERVER['SCRIPT_NAME'].

    But how does it not work exactly? Does it allways show home.php?

    D

  3. neilscott
    Member
    Posted 7 years ago #

    Okay, I managed to sort it out, here is the solution:

    
    <?php
    
      if(stristr($_SERVER['REQUEST_URI'], '/about')){
             include( TEMPLATEPATH . '/nav/about.php');
      }elseif(stristr($_SERVER['REQUEST_URI'], '/brands')){
             include( TEMPLATEPATH . '/nav/contact.php');
      }elseif(stristr($_SERVER['REQUEST_URI'], '/investor')){
             include( TEMPLATEPATH . '/nav/contact.php');
      }elseif(stristr($_SERVER['REQUEST_URI'], '/careers')){
             include( TEMPLATEPATH . '/nav/contact.php');
      }elseif(stristr($_SERVER['REQUEST_URI'], '/media')){
             include( TEMPLATEPATH . '/nav/contact.php');
      }elseif(stristr($_SERVER['REQUEST_URI'], '/contact')){
             include( TEMPLATEPATH . '/nav/contact.php');
      }else{
             include( TEMPLATEPATH . '/nav/home.php');
      } 
    
    ?>
    

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags