treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Simple If-Statement Not Working

  • Hey there,

    I have an if statement (not in Wordpress; just a simple PHP site) that refuses to work. Thought it was right, guess it's not?

    Code I have in between my HEAD tags:


    <?php if($page == 'obituaries') { ?>
    <link rel="stylesheet" type="text/css" href="/resources/css/superbox.css" media="all" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script&gt;
    <script type="text/javascript" src="resources/js/superbox.js"></script>
    <script type="text/javascript">
    $(function(){
    $.superbox.settings = {
    closeTxt: "Close",
    loadTxt: "Loading...",
    nextTxt: "Next",
    prevTxt: "Previous"
    };
    $.superbox();
    });
    </script>
    <?php } ?>



    Code I have after my BODY:


    <?
    $path = $_SERVER['PHP_SELF'];
    $page = basename($path);
    $page = basename($path, '.php');
    $dir = substr(strrchr(getcwd(), '/'), 1);
    ?>



    I also have the code from Chris Coyier to create a body ID on every page:


    <body id="<?= basename($_SERVER['PHP_SELF'], '.php')?>">



    But I can't figure out how to call a body id even if I wanted to try that way.

    Anybody have any thoughts?

    - Steph
  • It looks like you're defining your $page variable after you begin the if() statement. If the variable hasn't been set to "obituaries" yet, it shouldn't meet that condition.

    I think that's the problem anyways!
  • That would make sense, I'll try that!

    Thank you.

    - Steph
  • That worked, thank you!

    - Steph