Timbo Posted March 22, 2013 Share 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 Link to comment Share on other sites More sharing options...
interrobang Posted March 22, 2013 Share 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>"; } } ?> Link to comment Share on other sites More sharing options...
Luis Posted March 22, 2013 Share Posted March 22, 2013 Change your " in class declaration into ' Edit: Hmpf too Late Link to comment Share on other sites More sharing options...
Timbo Posted March 22, 2013 Author Share Posted March 22, 2013 Hahaha damn I knew that was such a dumb noob-error Tanks, next time i will know it Link to comment Share on other sites More sharing options...
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