Timbo Posted March 22, 2013 Posted March 22, 2013 Hey there, I'm on my first website using ProcessWire and I'm not a PHP-Crack 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
interrobang Posted March 22, 2013 Posted March 22, 2013 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>"; } } ?>
Luis Posted March 22, 2013 Posted March 22, 2013 Change your " in class declaration into ' Edit: Hmpf too Late
Timbo Posted March 22, 2013 Author Posted March 22, 2013 Hahaha damn I knew that was such a dumb noob-error Tanks, next time i will know it
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now