Jump to content

Styling home menu link


remove
 Share

Recommended Posts

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?

post-2698-0-88943000-1412457686_thumb.pn

post-2698-0-26399700-1412457761_thumb.pn

Link to comment
Share on other sites

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>";
}
  • Like 3
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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
  • Like 3
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...