0

I have a problem with an if statement, I'm trying to activate the page I'm at with php include, this is my include code;

<?php
echo '
<div class="container">
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="navbar-header">
                <a class="navbar-brand" href="/womsy/home.php">Womsy</a>
        </div>
            <ul class="nav navbar-nav">
                <li <?php if ($page = "home") {class=active;} else {echo "Failed to load active class."} ?><a href="?page=home">Home</a></li>
                <li><a href="?page=blog">Blog</a></li>
                <li><a href="?page=projects">Projects</a></li>
                <li><a href="?page=contact">Contact</a></li>
                <li><a href="?page=about">About</a></li>
            </ul>
    </div>
</nav>';
?>

This is how I include:

<?php
include ('php/includes/menu.php');
?>

So I'm trying to activate the "home" page, can someone help me with this?

Greetz

ka_lin
  • 9,329
  • 6
  • 35
  • 56

3 Answers3

0

Try this :

<?php
$page = "";
if(isset($_GET["page"]) && $_GET["page"] != "") {
$page = $_GET["page"];
}
?>

<div class="container">
<nav class="navbar navbar-inverse">
    <div class="container-fluid">
        <div class="navbar-header">
                <a class="navbar-brand" href="/womsy/home.php">Womsy</a>
        </div>
            <ul class="nav navbar-nav">
                <li <?php if ($page == "home") { echo "class='active'";} ?>><a href="?page=home">Home</a></li>
                <li <?php if ($page == "blog") { echo "class='active'";} ?>><a href="?page=blog">Blog</a></li>
                <li <?php if ($page == "projects") { echo "class='active'";} ?>><a href="?page=projects">Projects</a></li>
                <li <?php if ($page == "contact") { echo "class='active'";} ?>><a href="?page=contact">Contact</a></li>
                <li <?php if ($page == "about") { echo "class='active'";} ?>><a href="?page=about">About</a></li>
            </ul>
    </div>
</nav>

Mr. Engineer
  • 3,522
  • 4
  • 17
  • 34
0

You need fix your if block

if ($page = "home")

to

if ($page == "home")
Vinícius Medeiros
  • 2,763
  • 1
  • 11
  • 12
0

i think you have a error

<?php if ($page = "home") {class=active;} else {echo "Failed to load active class."} ?>

should be

<?php if ($page == "home") {class=active;} else {echo "Failed to load active class."} ?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Rafael
  • 9
  • 8