We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Here’s an adaptation of my ListMenuX snippet, originally developed for Etomite, based on the SimpleListMenu snippet. Hope someone finds it useful...

    // --------------------
    // Snippet: ListMenuX
    // --------------------
    // Version: 1.2
    // Date: 2005.05.31
    // [email protected]
    //
    // Based on the SimpleListMenu snippet.
    //
    // Note: This snippet will only show documents and 
    // folders at the current level and below.
    //
    // Credit for the base code goes to [email protected]
    // based on the SimpleListMenu snippet.
    //  
    // Usage:
    // [[ListMenuX?id=0&depth=2&divId=my-menu&activeLinkClass=currentMenuItem]] 
    //
    $id = !isset($id)?$modx->documentIdentifier:$id;
    $depth = !isset($depth)?0:$depth;
    $nodiv = !isset($nodiv)?false:$nodiv;
    $sDivId = empty($divId)?"":" id='$divId'";
    $sDivClass = empty($divClass)?"":" class='$divClass'";
    $sUlClass = empty($ulClass)?"":" class='$ulClass'";
    $sLiClass = empty($liClass)?"":" class='$liClass'";
    $sActiveLinkClass = empty($activeLinkClass)?"":" class='$activeLinkClass'";
    
    $children = $modx->getActiveChildren($id); 
    $menu = ""; 
    $childrenCount = count($children);
    if($children==false) {
    return $menu;
    }
    if ($nodiv==false) $menu .= "<div$sDivId$sDivClass>\n";
    $menu .= "<ul$sUlClass>\n"; 
    foreach ($children as $child)
    {
    $level = ($depth < 1)?1:$depth;
    
    // If child is current document, add activeLink class
    if ($child['id']==$modx->documentIdentifier)
    { 
    $menu .= "<li$sLiClass><a$sActiveLinkClass href='[~".$child['id']."~]' title='".$child['description']."'>".$child['pagetitle']."</a>";
    } 
    else 
    {
    $menu .= "<li$sLiClass><a href='[~".$child['id']."~]' title='".$child['description']."'>".$child['pagetitle']."</a>";
    }
    
    if ($depth > 1) {
    $subDepth = $depth - 1;
    $suffix = "-nested";
    if (($snippetOut = $modx->runSnippet('ListMenuX', array('id'=>$child['id'],
    		'nodiv'=>true, 
    		'divId'=>!empty($divId)?$divId.$suffix:'', 
    		'divClass'=>!empty($divClass)?$divClass.$suffix:'', 
    		'ulClass'=>!empty($ulClass)?$ulClass.$suffix:'', 
    		'liClass'=>!empty($liClass)?$liClass.$suffix:'',
    		'activeLinkClass'=>!empty($activeLinkClass)?$activeLinkClass:'', 
    		'depth'=>$subDepth
    	))) != false)
    {
    $menu .= $snippetOut;
    } 
    }
    
    $menu .= "</li>\n";
    
    }
    
    $menu .= "</ul>\n";
    if ($nodiv==false) $menu .= "</div>\n";
    
    return $menu;
    
    • Excellent! I was just thinking of this at 3AM this morning when I couldn’t sleep! I don’t know whether to be overjoyed at the right tool at the right time, or be depressed because you guys are so far ahead of me!
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4673
        • 577 Posts
        hehe, just be depressed wink


        I’m in the same boat since I haven’t been focusing on the code sad
          Tangent-Warrior smiley
          • 33337
          • 3,975 Posts
          Great work Jason,

          Thanks for sharing nice stuff smiley

          Regards,

          zi
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 34162
            • 1 Posts
            will this menu work properly with the current tp3 and the sibdir aliases option. The curent list menu really gets confused on this.

            for instans it will go like this

            http://liquidthemes.com/home.web
            http://liquidthemes.com/theme-testing.web
            http://liquidthemes.com/theme-testing/wordpress-themes.web
            http://liquidthemes.com/theme-testing/theme-testing/wordpress-themes/rin.web

            at any rate you get the idea I end up with extra subdirs which or course does not work correctly.
            • Quote from: webmedic at Jul 19, 2005, 05:41 PM

              will this menu work properly with the current tp3 and the sibdir aliases option. The curent list menu really gets confused on this.

              for instans it will go like this

              http://liquidthemes.com/home.web
              http://liquidthemes.com/theme-testing.web
              http://liquidthemes.com/theme-testing/wordpress-themes.web
              http://liquidthemes.com/theme-testing/theme-testing/wordpress-themes/rin.web

              at any rate you get the idea I end up with extra subdirs which or course does not work correctly.

              I believe it will work, but as will any site you create using this option, you must either use absolute paths from the webserver root (instead of the usual relative paths from the site root), create templates for each directory level with the appropriate paths, OR you can add a base tag to your template( s ) HEAD tag (before referencing any other resources via relative URL) that maintains the base href of all pages as the site root (my preferred method):

              <base href="http://localhost/some/odd/path/mysite/">


              I believe we may provide automatic insertion of this base tag in a future release when the use Friendly Alias Paths option is selected, or at least an option to do this when selected.
                • 34162
                • 1 Posts
                yes I’m aware of thtat and have already correct all the themes on my site acordingly. The only issue I’m having si the way the listmenu snippet genereates the urls. AS you end up with multiples of the same sib-dir.

                On a side not I’m also finding out just how horrible the orignial is one the database. I’m getting 1 sql call for evey link in the menu. it wonders me why all the links aren’t fetched with a single sql call. That way you could just pull an array of links and spit out the relivent parts of the array. If done properly I suppose depending on how the db is done it would be possible to use the db and make it select on the content you want and use limit to limit the results. It’s amazing to me that most poeple are using php to do the work that the db is supposed to be doing.
                • Quote from: webmedic at Jul 20, 2005, 05:46 AM

                  On a side not I’m also finding out just how horrible the orignial is one the database. I’m getting 1 sql call for evey link in the menu. it wonders me why all the links aren’t fetched with a single sql call. That way you could just pull an array of links and spit out the relivent parts of the array. If done properly I suppose depending on how the db is done it would be possible to use the db and make it select on the content you want and use limit to limit the results. It’s amazing to me that most poeple are using php to do the work that the db is supposed to be doing.

                  Indeed, I chose to use the API’s to do that rather than one big SQL call in case data structures were changed as the product changed. There needs to be an abstraction layer between the data access and the components, and this is all we’ve got for now; but producing a document map would be a good API addition in my opinion, and could lead to the development of a more efficient menu snippet.

                  As for the sibling problem you are having, I’m not sure I understand. With my <base href=""> solution, it generates the URL’s perfectly for me. Can you explain more about this issue?
                  • +1 on adding a doc map API addition... a big +1.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 34162
                      • 1 Posts
                      Quote from: OpenGeek at Jul 20, 2005, 06:04 AM

                      As for the sibling problem you are having, I’m not sure I understand. With my <base href=""> solution, it generates the URL’s perfectly for me. Can you explain more about this issue?

                      no you had it right. I had talked to ryan about some of the changes in the new version and he had mentioned the the listmenu would ne to be tweeked some adn I assumed it was the core product that was spitting out the funky urls.

                      As soon as I added the base href it fixed the issue. Thats and sorry for the waste of time.

                      by the way ryan the reason I noticed the sql issue is that I’m getting a fair number of themes up there and I started noticing my sql usage going through the roof. The menu as about the only thing changing so it would be good to find some solution to this now rather than later.

                      Either that or we need a theme changer.