Jump to content

newbie140

Members
  • Posts

    7
  • Joined

  • Last visited

Posts posted by newbie140

  1. Thank you very much Soma and drogo for your help..i've already modified the simpleNavigation module to display what i want....thanks more power...

    Thanks again Soma, that's exactly what i did in the module...forgive me im weak in php...hehehe....thanks

  2. hi drogo..thanks for discussing with me...

    Home About Media Bills & Resolutions Publications Projects Gallery Contact Us

    thats what i want..even if i will go to "about" page or other page, the navigation structure will still looks the same...thanks

  3. If it's still relevant. I took Apeisa's code from the above-mentioned topic and modified it a bit and it seems to work the way you wanded, Soma :)

    <?php
    
    function treeMenu(Page $page = null, $depth = 1, $id = null) {
    
               $depth -= 1;
    
               if(is_null($page)) $page = wire('page');
               if(!is_null($id)) $id = " id='$id'";
    
               $out = "\n<ul$id>";
    
               $parents = $page->parents;
    
               // This is where we get pages we want. You could just say template!=news-item
               foreach($page->children() as $child) {
                       $class = "level-" . count($child->parents);
                       $s = '';
                       if($child->numChildren && $depth > 0 ) {
                               $s = str_replace("\n", "\n		", treeMenu($child, $depth));
                       }
    
                       $class .= " page-{$child->id}";
                       $class = " class='$class'";
                       $out .= "\n	<li$class>\n		<a$class href='{$child->url}'>{$child->title}</a>$s\n	</li>";
               }
           $out .= "\n</ul>";
    
           return $out;
    }
    
    //parameters: current page, menu depth, ul menu id
    $menu = treeMenu($page, 3, "myMenu");
    
    echo $menu;

    You shoud pass depth as a second parameter. By default it will output only one level.

    Edit: optimized code a bit

    I like this code, but i need the "Home" menu to be always included...thanks..please help..

  4. Hi, I'm new to PW and php, and i need your help guys. My problem is im trying to include the "Home" menu to this code below that

    slkwrm posted..can anyone help me?..tnx

    function treeMenu($page, $depth = 1, $id = null) {

    $depth -= 1;

    if(is_null($page)) $page = wire('page');

    if(!is_null($id)) $id = " id='$id'";

    $out = "\n<ul$id>";

    $parents = $page->parents;

    // This is where we get pages we want. You could just say template!=news-item

    foreach($page->children() as $child) {

    $class = "level-" . count($child->parents);

    $s = '';

    if($child->numChildren && $depth > 0 ) {

    $s = str_replace("\n", "\n ", treeMenu($child, $depth));

    }

    $class .= " page-{$child->id}";

    $class = " class='$class'";

    $out .= "\n <li$class>\n <a$class href='{$child->url}'>{$child->title}</a>$s\n </li>";

    }

    $out .= "\n</ul>";

    return $out;

    }

    //parameters: current page, menu depth, ul menu id

    $menu = treeMenu($pages->get("/"), 2, "myMenu");

    echo $menu;

×
×
  • Create New...