froot Posted April 13, 2020 Share Posted April 13, 2020 I'm trying to put pages in the main menu on condition that the checkbox, a field named "menu_item" that I created, is checked on that specific page. so in the _head it says: 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' aria-current='true'><span class='visually-hidden'>Current page: </span><a href='$child->url'>$child->title</a></li>"; } else { echo "<li><a href='$child->url'>$child->title</a></li>"; } } so I figured I add elseif($page->child($menu_item) == 1) { echo "<li><a href='$child->url'>$child->title</a></li>"; } but no matter how I twist and turn it it doesn't work. Is is $page->child($menu_item) or $child->menu_item or $page->child->menu_item or … thanks for help Fred Link to comment Share on other sites More sharing options...
cehlo Posted April 14, 2020 Share Posted April 14, 2020 Hi there, first the answer depends on that if your array "children" is PageArray. If yes I believe if you want currently viewed page you must check if child->id is simalar like page->id not parent->id. Secondly if you want to check if checkbox is checked the right way will be: $child->checkbox_field == 1 Also I think you know this but else if must be put before else statement :D. Lastly maybe consider using custom menu builder for this. Menu Builder. In addition this checking can be done before building actual markup for menu. So you can consider this solution an then you won't need else if. $menuPages = $pages->find('menu_item=1'); //and add additional selectors for template etc., also you can use selector like this for method children() Cheers. 2 Link to comment Share on other sites More sharing options...
froot Posted April 14, 2020 Author Share Posted April 14, 2020 Hi, yes I used Menu Builder instead, does pretty much what I need. Thanks a lot though. Fred 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