ngrmm Posted March 24, 2016 Share Posted March 24, 2016 this is my page-tree –projects –– project A –– project B –– project C –categories –– x –– y every project has a page-field and the options are the children of categories. the categorie are the menu of the site. how ist possible to falg the right <li> on a project-site? this my code and i don't know how select/flag only the <li> of the current page category <ul> <?php $root = $pages->get("1052"); $children = $root->children(); foreach($children as $child) { // for the other sites $class = $child === $page ? " class='on'" : ''; // project $ci = $child->id; $pc = $page->category; $class2 = $ci === $pc ? " class='on2'" : ''; echo "<li $class $class2 ><a href='{$child->url}'>{$child->title}</a></li>"; } ?> </ul> Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 24, 2016 Share Posted March 24, 2016 // project $class2 = $page->category->has($child->id) ? " class='on2'" : ''; 1 Link to comment Share on other sites More sharing options...
ngrmm Posted March 29, 2016 Author Share Posted March 29, 2016 thx but it doesn't work it outputs nothing Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 29, 2016 Share Posted March 29, 2016 What's the intended structure the code should produce? Link to comment Share on other sites More sharing options...
ngrmm Posted March 29, 2016 Author Share Posted March 29, 2016 for example on the category-x-page, it should produce this: <ul> <li class="on"><a>category x</a><li> <li><a>category y</a><li> <li>…<li> </ul> an it should look like this when i'm on a project-page, which has the category-x chosen in a page-field (select): <ul> <li class="on2">category x<li> <li>category y<li> <li>…<li> </ul> Link to comment Share on other sites More sharing options...
ngrmm Posted March 29, 2016 Author Share Posted March 29, 2016 this makes totally sense, but it just doesn't work. // project $class2 = $page->category->has($child->id) ? " class='on2'" : ''; i tried it this way, still no success <ul> <?php $root = $pages->get("1052"); $children = $root->children(); foreach($children as $child) { // for other pages $class = $child === $page ? " class='on'" : ''; // project if($page->template->name == 'project'){ $ci = $child->id; $pc = $page->category; if($pc == $ci) { echo "<li class='on2'><a href='{$child->url}'>{$child->title}</a></li>"; } else { echo "<li ><a href='{$child->url}'>{$child->title}</a></li>"; } } else { echo "<li $class ><a href='{$child->url}'>{$child->title}</a></li>"; } } ?> </ul> Link to comment Share on other sites More sharing options...
tpr Posted March 29, 2016 Share Posted March 29, 2016 is "$page->category" a single page? Just make sure it returns the ID when you compare. Link to comment Share on other sites More sharing options...
ngrmm Posted March 29, 2016 Author Share Posted March 29, 2016 yes it's a single-page and it returns the id Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 29, 2016 Share Posted March 29, 2016 If it's single page than use "$page->category->id == $child->id" 1 Link to comment Share on other sites More sharing options...
Christophe Posted March 29, 2016 Share Posted March 29, 2016 It should be $root = $pages->get(1052); and not $root = $pages->get("1052"); , shouldn't it? Is it the id, or the name of the page? Link to comment Share on other sites More sharing options...
kongondo Posted March 29, 2016 Share Posted March 29, 2016 It should be $root = $pages->get(1052); and not $root = $pages->get("1052"); , shouldn't it? Is it the id, or the name of the page? Either will work 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