jeudi 18 août 2016

Why is my conditional statement not working?

I'm trying to use one header.php to process both my public pages and my admin pages using conditional statements. I used this technique in a website using procedural PHP, but I have switched over to OOP PHP. These if else statements should still work, so I don't know what I'm doing wrong.

So this code is at the top of my header.php wrapped in php tag.

if (!isset($layout_context)) {
    $layout_context = "public"; 
    } 

Then in my ....... I have sections of code like this

<?php if($layout_context == "public") { ?>
  <header id="home">
<?php } elseif($layout_context == "admin") { ?>
  <header id="cms-pages">
<?php } ?>

Then in all my pages I put this code at the top

<?php $layout_context = "public"; ?>

or

<?php $layout_context = "admin"; ?>

As far as I can tell my pages are only grabbing the information in the "public" and not the "admin". Any thought?

Aucun commentaire:

Enregistrer un commentaire