IF statement for blogroll

Discussion in 'PHP' started by mark_s, Mar 3, 2008.

  1. #1
    I have a links section on my website that is sitewide but I would like to only display various external links depending on the page the person is on rather than having a bunch of sitewide links.

    Would someone kindly tell me some PHP code that allows me to do this?

    This is my site, the links section is at the bottom left.
     
    mark_s, Mar 3, 2008 IP
  2. able

    able Peon

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can store various links that are associated with the specific page, then load them based on the url being requested. Check the $_SERVER variables to find out which page the browser has requested.
     
    able, Mar 3, 2008 IP
  3. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #3
    Well you can try something like:
    
    if($page = "home") {
    //display home links 
    }
    if($page = "about") {
    //display about page links 
    }
    
    PHP:
    and so on ... ? That help?
     
    smatts9, Mar 3, 2008 IP
  4. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's the sort of thing I'm looking for but what you gave me doesn't work.
     
    mark_s, Mar 3, 2008 IP
  5. smatts9

    smatts9 Active Member

    Messages:
    1,089
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    88
    #5
    Maybe something as such:

    
    <?
    if($_SERVER['REQUEST_URI'] == "/index.php") {
    echo "links for homepage";
    }
    if($_SERVER['REQUEST_URI'] == "/about.php") {
    echo "links for about.php";
    }
    ?>
    
    PHP:
     
    smatts9, Mar 3, 2008 IP
  6. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    That worked great, thank you!!
     
    mark_s, Mar 3, 2008 IP