Jump to content

PHP Menu - Syntax error


Timbo
 Share

Recommended Posts

Hey there,

I'm on my first website using ProcessWire and I'm not a PHP-Crack :P

So my Problem is: I want to make a horizontal nav menu, where the <li> element has the class="active" for the current page.

so here my PHP code:

         <?php
        $root = $pages->get("/");
        $children = $root->children();
        foreach($children as $child)
        {
            if($child === $page)
            {
syntaxerror---> echo "<li class="active"><a href='{$child->url}'>{$child->title}</a></li>";
            }
            else
            {
                echo "<li><a href='{$child->url}'>{$child->title}</a></li>";
            }
        }
        ?>
 

anyone got an Idea? :-[

Thanks

Link to comment
Share on other sites

Your quotes around "active" are the problem, try this:


<?php

$root = $pages->get("/");

$children = $root->children();

foreach ($children as $child) {

if ($child === $page) {

// I changed "active" to 'active' so your quotes dont break the echo.

echo "<li class='active'><a href='{$child->url}'>{$child->title}</a></li>";

} else {

echo "<li><a href='{$child->url}'>{$child->title}</a></li>";

}

}

?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...