dimanche 26 juillet 2015

Using basename(__FILE__) to determine the page's name to change the title doesn't work

It is pretty simple, but I think I'm missing something crucial here:

<?php 
        $title = " | Unlimited Motors";
if (basename(__FILE__) == "index.php") {
    global $title;
    $title = "Home"." | Unlimited Motors";
}
if (basename(__FILE__) == "contact.php") {
    global $title;
    $title = "Contact Us"." | Unlimited Motors";
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title><?php echo $title; ?></title>

You'd think something so simple would work.
Alas, it doesn't. The echo $title; part inside the <title></title> doesn't pick up the changed variable. It simple displays " | Unlimited Motors" as it was without the if () changing it.
I'm a little confused at these global variables and stuff, so can anyone explain the error in here?

Aucun commentaire:

Enregistrer un commentaire