Jump to content

navigation by page-field


ngrmm
 Share

Recommended Posts

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

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

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

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...