remove Posted October 4, 2014 Posted October 4, 2014 Hi, I need help with the following. In my menu I've added a child called Home to show in the menu. The Child Home is attached to a template with the following redirect. <?php $session->redirect('/'); ?> When Home is active, it losses styling because there is no .current class when the Home is active. I've attached a screenshot. Is there a solution for this?
adrian Posted October 4, 2014 Posted October 4, 2014 I am not totally sure why you have the child Home page. If it's just to get it to appear in the front-end menu, then there are much better ways. $homepage = $pages->get("/"); $children = $homepage->children; $children->prepend($homepage); foreach($children as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; } 3
remove Posted October 5, 2014 Author Posted October 5, 2014 I am not totally sure why you have the child Home page. If it's just to get it to appear in the front-end menu, then there are much better ways. $homepage = $pages->get("/"); $children = $homepage->children; $children->prepend($homepage); foreach($children as $child) { $class = $child === $page->rootParent ? " class='active'" : ''; echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>"; } Thx!
SiNNuT Posted October 5, 2014 Posted October 5, 2014 Note that if you would want to insert the homepage somewhere else, let's say to center it in a nav (in this case after 'Werk') PW comes with more handy stuff. All (or at least most) available on the http://cheatsheet.processwire.com/ $homepage = $pages->get('/'); $menu_items = $homepage->children; $menu_items->insertAfter($homepage, $menu_items[1]); // insert $homepage after the second homepage child 3
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