Jump to content

Sidebar Navigation.


Jon
 Share

Recommended Posts

Hello All,

Iam trying to figure out how to list all pages in a sidebar steaming from parent page after the home.

For example my sitemap is

Home
--Gallery
---Boats
---Wildlife
----Birds
 

So for my sidebar I would like to list from Gallery all the way down to birds. Including Gallery at the top

I've managed to get the sidebar working on Gallery but as soon as I head into a child I lose the Parent.

The code Iam using is hashed up of a couple of other Topic on the forums.

 

  $p = $page;
  $out ="";
  if ($p->numChildren) {
    $out .="<div class='sub-pages'>";
    $out .="<ul class='menu vertical'>";
    if ($p->id == $page->id) {
      $out .= "<li><a class='active' href='{$p->url}'>{$p->title}</a></li>";
    }else{
      $out .= "<li><a href='{$p->url}'>{$p->title}</a></li>";}}

  foreach($p->children as $child) {
    
    // check if this child is in parents or direct parent of current page
    if($page->parents->has($child) || $child === $page || $child === $page->parent) $class = "active"; else $class = '';
       if (strlen(trim($child->link_text)) > 0){
                   $link = $child->link_text;}
                  else 
                    {$link = $child->title;}
    $out .= "<li><a class='$class' href='{$child->url}'>{$link}</a>";
    //if ($class=="active") {
    if($child->numChildren > 0){
      
      // check if this child is in parents or direct parent of current page

      $out .= "<ul class='menu vertical'>";
      
      foreach($child->children as $childchild) {
        
        if($childchild === $page || $childchild === $page->parent) $class = "active"; else $class = '';
        if (strlen(trim($childchild->link_text)) > 0){
                   $link = $childchild->link_text;}
                  else 
                    {$link = $childchild->title;}
        $out .= "<li><a class='$class' href='{$childchild->url}'>{$link}</a></li>";
      }
      $out .= "</ul>";
    }
  //}
    $out .= "</li>";
  }

    $out .= "</ul>";
    $out .= "</div>";
    echo $out;

 

Link to comment
Share on other sites

Hello Robin,

Thanks for that using $page->rootParent solved the issue. I've taken a look into MarukpSimpleNavigation Ill definitely used that next and save myself some work 

Many Thanks :)

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