Marcel Epp Posted August 26, 2015 Share Posted August 26, 2015 Hi, i need some help with the navigation menu. How can i add a link to an anchor? I used this to display my sites. The menu renders fine. After the second entry i would link to screen2. How can i do that? <?php include("./head.php"); ?> <body> <section id="screen1">text <nav> <ul> <?php // top navigation consists of homepage and its visible children $homepage = $pages->get('/'); $children = $homepage->children(); // make 'home' the first item in the navigation $children->prepend($homepage); // render an <li> for each top navigation item foreach($children as $child) { if($child->id == $page->rootParent->id) { // this $child page is currently being viewed (or one of it's children/descendents) // so we highlight it as the current page in the navigation echo "<li class='current'><a href='$child->url'>$child->title</a></li>"; } else { echo "<li><a href='$child->url'>$child->title</a></li>";}} // output an "Edit" link if this page happens to be editable by the current user if($page->editable()) { echo "<li class='edit'><a href='$page->editUrl'>Seite bearbeiten</a></li>"; }?> </ul> </nav> </section> <section id="screen2"></section> <?php include("./footer.php"); ?> Link to comment Share on other sites More sharing options...
mr-fan Posted August 26, 2015 Share Posted August 26, 2015 <?php // top navigation consists of homepage and its visible children $homepage = $pages->get('/'); $children = $homepage->children(); // make 'home' the first item in the navigation $children->prepend($homepage); $count_children = 0; // render an <li> for each top navigation item foreach($children as $child) { //change the css class if child is current $class= ($count_children == 0) ? " current " : ""; //count entries $count_children++; //check if we got the second/third or something else item if ($count_entries == 1) //counting starts by 0 so second item is 1! echo custom link echo "<li class='$class'><a href='#screen2'>My custom title</a></li>"; } else { echo "<li class='$class'><a href='$child->url'>$child->title</a></li>";} } ?> just written in the browser - may need some testing...use counting items to add some items between. Changed the usage of the current/active class to some easier function to make it a little more DRY... regards mr-fan Link to comment Share on other sites More sharing options...
Marcel Epp Posted August 26, 2015 Author Share Posted August 26, 2015 Thanks for your answer! Didn't get it to work I gave Menubuilder a second change. Works now. But i have to disable the language module.... Link to comment Share on other sites More sharing options...
mr-fan Posted August 26, 2015 Share Posted August 26, 2015 Didn't work is a not acceptable answer....;-) What did not work? Error message? Should work.. I will try tomorrow a real world example. Just short from mobile. Link to comment Share on other sites More sharing options...
mr-fan Posted August 27, 2015 Share Posted August 27, 2015 So my errors show me that i've forgot one brace and set one wrong var name...and changed the condition to check the class on current... so this have to work as expected. Have you debug mode on in config.php? Get you PHP errors? Here is the right example: // top navigation consists of homepage and its visible children $homepage = $pages->get('/'); $children = $homepage->children(); // make 'home' the first item in the navigation $children->prepend($homepage); $count_children = 0; // render an <li> for each top navigation item foreach($children as $child) { //change the css class if child is current $class= ($child === $page->rootParent) ? " current " : ""; //count entries $count_children++; //check if we got the second/third or something else item if ($count_children == 1) { //counting starts by 0 so second item is 1! echo custom link echo '<li class="'.$class.'"><a href="'.$homepage->url.'#screen2">My custom title</a></li>'; } else { //normal menu entries echo '<li class="'.$class.'"><a href="'.$child->url.'">'.$child->title.'</a></li>';} } best regards mr-fan 1 Link to comment Share on other sites More sharing options...
Marcel Epp Posted August 27, 2015 Author Share Posted August 27, 2015 wow! thanks for your help!!! It is working now 1 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