ngrmm Posted March 24, 2016 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>
LostKobrakai Posted March 24, 2016 Posted March 24, 2016 // project $class2 = $page->category->has($child->id) ? " class='on2'" : ''; 1
LostKobrakai Posted March 29, 2016 Posted March 29, 2016 What's the intended structure the code should produce?
ngrmm Posted March 29, 2016 Author 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>
ngrmm Posted March 29, 2016 Author 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>
tpr Posted March 29, 2016 Posted March 29, 2016 is "$page->category" a single page? Just make sure it returns the ID when you compare.
ngrmm Posted March 29, 2016 Author Posted March 29, 2016 yes it's a single-page and it returns the id
LostKobrakai Posted March 29, 2016 Posted March 29, 2016 If it's single page than use "$page->category->id == $child->id" 1
Christophe Posted March 29, 2016 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?
kongondo Posted March 29, 2016 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
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