We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4095
    • 372 Posts
    I notice on the MODx homepage they are using a method of hiding child items from the menu unless they are under the current menu.

    #links ul ul {
    	display:none;
    }
    
    #links li.here ul {
    	display:block;
    }
    



    How do I get this to work in ListMenuX? I played around a bit in the Snippet but trail and error isn’t working for me tonight smiley
      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
      Admin Sandbox Login: sandbox Password: castle
    • I had a similar issue; needed to have the current link li have a "current" class. I added this to the snippet:

      $sActiveListClass = empty($activeListClass)?"":" class=’$activeListClass’";

      This gave me the option of setting a class for the active link’s li element. Then I changed this:

      // If child is current document, add activeLink class
      if ($child['id']==$modx->documentIdentifier)
      { 
      $menu .= "<li$sActiveListClass><a$sActiveLinkClass href='[~".$child['id']."~]' title='".$child['description']."'>".$child['pagetitle']."</a>";
      } 



      Now I have a class for both the current active LI and the current active a element. The CSS does the rest.

      <ul>
      <li><a href=’index.php?id=22’ title=’’>Downloads</a></li>
      <li><a href=’index.php?id=1’ title=’sottwell.com home page’>Welcome</a></li>
      <li class=’current’><a class=’active’ href=’index.php?id=13’ title=’’>Links</a></li>
      <li><a href=’index.php?id=3’ title=’Page that shows some visitor statistics for the site.’>Site statistics</a></li>
      <li><a href=’index.php?id=4’ title=’This page allows you to search the site.’>Search this site</a></li>
      </ul>

      Here’s a couple of good articles on how:

      http://www.alistapart.com/articles/hybrid
      http://www.positioniseverything.net/css-dropdowns.html
        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
        • 4095
        • 372 Posts
        Cool that gave me an active link class I needed...... now I am going crazy trying to style it.

        The list looks like the following
        <div id='menu'>
        <ul>
        <li><a href='home.html' title='Homepage'>Home</a></li>
        <li><a href='news.html' title='News Articles'>News</a></li>
        <li><a class='current' href='courses.html' title='Course List'>Courses</a><ul>
        <li><a href='emrl2.html' title='EMR Level 2'>EMR L2</a></li>
        </ul>
        </li>
        <li><a href='calander.html' title='calander'>Calander</a></li>
        </ul>
        </div>


        At this stage just trying to highlight each line so I can find the correct references. So to highlight the entire menu I used:

        #menu ul
        	display: block;
        	color: #000080;
        	font-weight: 800;


        Also #menu ul li works. To highlight the active pearent I used

        #menu ul li a.current

        Now this is where the issue is, to highlight the child I tried the following, but none worked
        #menu ul li a.current ul
        #menu ul li a.current ul li
        #menu ul li a.current li
        #menu a.current ul

        I can hide it by using #menu ul ul

        I’m sure its simple, but I can’t get it to work. huh
          [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
          Admin Sandbox Login: sandbox Password: castle
        • It looks like there’s an extra random closing LI and UL in your code. Or a missing opening one at the top. Is that a typo?
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • I noticed it also; haven’t had the energy to see where it comes from; too hot. Maybe in the morning.
              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
            • Quote from: briggsys at Aug 05, 2005, 12:18 PM

              #menu ul li a.current ul
              #menu ul li a.current ul li
              #menu ul li a.current li
              #menu a.current ul

              Get rid of the a.current, cause the anchor tags do not contain the second level UL’s. You need a class on the li called current and then it would be...

              #menu ul li.current ul {...}


              or

              #menu li.current ul { ... }
                • 4095
                • 372 Posts
                It looks like there’s an extra random closing LI and UL in your code. Or a missing opening one at the top. Is that a typo?

                Nope, that was cut n pasted from the HTML source after ListMenuX generated it. If you’re talking about the following section of code, Courses is the pearent item and EMR L2 is the child. All the other menu items have no siblings at this stage.

                <li><a class='current' href='courses.html' title='Course List'>Courses</a><ul>
                <li><a href='emrl2.html' title='EMR Level 2'>EMR L2</a></li>
                </ul>
                </li>


                Get rid of the a.current, cause the anchor tags do not contain the second level UL’s. You need a class on the li called current and then it would be...

                It appears that the pearent item is List Item, and before it closes it has another Unordered List, which is the sibling which has its own List Item, which closes and then the Unordered List and the original pearent List Item closes.

                The current page is the Courses which is "a.class=current", if i drop that, it no longer highlights the current page.

                I wonder if the ListMenuX snippit should be outputting it in a different way? Maybe a class for the sibling s under the current menu? Then it would have been easy. Also notice Sottwells is different and does have a LI class (current) and a.class (active)

                <li class='current'><a class='active' href='index.php?id=13' title=''>Links</a></li>


                Sorry if I am missing something here, I have searched examples all over the Net, looked at other pages and just can’t get it to work.

                  [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
                  Admin Sandbox Login: sandbox Password: castle
                • There are a thousand ways to accomplish menu styling, and everyone has their own goals and objectives when designing them.  ListMenuX was a simple, recursive list menu maker with the ability to allow you to specify style classes for each element, and even append suffixes to them to distinguish different levels.  I have many versions of this all over the web that work the way I needed them to.  Your requirements for the generated markup may be different, as may be your approach to styling them with CSS, so I’m sure you’ll need to modify the script to get it to behave exactly as you want it to (as sottwell did)..

                  That said, we did not use ListMenuX on the MODx CMS site, as we already had a another snippet which added a hardcoded class called .here to the first level LI that is the parent of the current page, so you can highlight the parent and current page with appropriate styles.

                  In the meantime, here is the menu snippet from the MODx CMS site, which is being refactored (by allowing a lot more configuration parameters, such as id, class, and style selectors for each list, element, and/or link, optional surrounding divs, etc.) for release as the default menu building snippet in the next release, if you’re interested in that specific menu behavior:

                  // ###########################################
                  // Drop Menu                                 #
                  // ###########################################
                  // Create navigation that allows for non-content section folders
                  // Can be styled pretty much in any way to function as a 
                  // that link to the first child of the folder.
                  //
                  // Developed by Vertexworks.com and Opengeek.com for modxcms.com
                  // Feel free to use if you keep this header and credits in place
                  //
                  // Inspired by List Site Map by Jaredc and SimpleList by Bravado
                  
                  
                  // ###########################################
                  // Configuration parameters                  #
                  // ###########################################
                  // $siteMapRoot [int]
                  // The parent ID of your root. Default 0. Can be set in 
                  // snippet call with startDoc (to doc id 10 for example):
                  // [[DropMenu?startDoc=10]]
                  $siteMapRoot = 0;
                  
                  // $titleOfLinks [ string ]
                  // What database field do you want the title of your links to be?
                  // The default is pagetitle because it is always a valid (not empty)
                  // value, but if you prefer it can be any of the following:
                  // id, pagetitle, description, parent, alias, longtitle
                  $titleOfLinks = 'pagetitle';
                  
                  // $removeNewLines [ true | false ]
                  // If you want new lines removed from code, set to true. This is generally
                  // better for IE when lists are styled vertically. 
                  $removeNewLines = false;
                  
                  // $maxLevels [ int ]
                  // Maximum number of levels to include. The default 0 will allow all
                  // levels. Also settable with snippet variable levelLimit:
                  // [[DropMenu?levelLimit=2]]
                  $maxLevels = 0;
                  
                  // $showDescription [true | false]
                  // Specify if you would like to include the description
                  // with the page title link.
                  $showDescription = false;
                  
                  // $selfAsLink [ true | false ]
                  // Define if the current page should be a link (true) or not
                  // (false)
                  $selfAsLink = false;
                  
                  // $pre [ string ]
                  // Text to append before links inside of LIs
                  $pre = '';
                  
                  // $post [ string ]
                  // Text to append before links inside of LIs
                  $post = '';
                  
                  // Need to add ability to add hover zones
                  
                  // Styles
                  // static for now, need to convert to pass into the snippet
                   // .topnav    span surrounding current page if $selfAsLink is false
                   // .subnav    description of page
                   // .here      you are here
                  
                  // ###########################################
                  // End config, the rest takes care of itself #
                  // ###########################################
                  
                  // Initialize
                  $MakeMap = "";
                  $siteMapRoot = (isset($startDoc))? $startDoc : $siteMapRoot ;
                  $maxLevels = (isset($levelLimit))? $levelLimit : $maxLevels ;
                  $ie = ($removeNewLines)? '' : "\n" ;
                  
                  // Overcome single use limitation on functions
                  global $MakeMap_Defined;
                  
                  if( !isset( $MakeMap_Defined ) ) {
                    function MakeMap($callBy, $listParent, $listLevel, $description, $titleOfLinks, $maxLevels, $inside, $pre, $post, $selfAsLink, $ie, $activeLinkIDs){
                  
                          $children = $callBy->getActiveChildren($listParent, 'menuindex', 'ASC', 'id, pagetitle, description, isfolder, content, parent, alias, longtitle' );
                  
                       if(is_array($children) && !empty($children)) {
                  
                           $numChildren = count($children);
                           // determine if it's a top category or not
                           $toplevel = !$inside;
                           $output = ($toplevel)? '<ul class="topnav">'.$ie : $ie.'  <ul class="subnav">'.$ie ;
                  
                           //loop through and process subchildren
                           foreach($children as $child) {
                               // figure out if it's a containing category folder or not 
                               $numChildren--;
                               $isFolder = $child['isfolder'];
                                           $itm = "";
                  
                                           if (!$inside) {
                                               $itm .= (!$selfAsLink && ($child['id']==$callBy->documentIdentifier))?
                                                   $pre.$child['pagetitle'].$post :
                                                   '<a href="[~'.$child['id'].'~]" title="'.$child['longtitle'].'">'.$pre.$child['pagetitle'].$post.'</a>' ;
                                           } elseif ($isFolder  && $inside) { 
                                               $itm .= '<a href="[~'.$child['id'].'~]" title="'.$child['longtitle'].'">'.$child['pagetitle'].'</a>';
                                           } else {
                                               $itm .= ($child['alias'] > '0')? '<a href="[~'.$child['id'].'~]" title="'.$child['longtitle'].'">'.$child['pagetitle'].'</a>': '<span>'.$child['pagetitle'].'</span>';
                                           }
                  
                               // loop back through if the doc is a folder and has not reached the max levels
                               if ($isFolder && (($maxLevels==0) || ($maxLevels > $listLevel+1 ))) {
                                   $itm .= MakeMap($callBy, $child['id'], $listLevel+1, $description, $titleOfLinks, $maxLevels, true, $pre, $post, $selfAsLink, $ie, $activeLinkIDs);
                               }
                  
                               if ($itm && !$selfAsLink && ($child['id']==$callBy->documentIdentifier) ) {
                                   $output .= "    <li class=\"here".($numChildren==0?' last':'')."\">$itm</li>$ie";
                               } elseif ($itm) {
                                   if($numChildren==0) {
                                       $class='last';
                                   }
                                   if(is_array($activeLinkIDs)) {
                                       if(in_array($child['id'],$activeLinkIDs)) {
                                           $class.=($class?' ':'').'here';
                                       }
                                   }
                                   if($class) {
                                       $class = ' class="'.$class.'"';    
                                   }
                                   $output .= "<li".$class.">$itm</li>$ie";
                                   $class='';
                               }
                           }
                           $output .= "</ul>$ie";
                          }
                          return $output;
                      }    
                  $MakeMap_Defined = true;
                  }
                  
                  $currentID = $modx->documentObject['id'];
                  $parentID = $currentID;
                  
                  // find the parent docs of the current "you-are-here" doc
                  // used in the logic to mark parents as such also
                  while($parentID != $siteMapRoot && $parentID!=0) {
                      $parent = $modx->getParent($parentID,0);
                      if($parent) {
                          $parentID = $parent['id'];
                          $activeLinkIDs[] = $parentID;
                      } else {
                          $parentID = 0;
                      }
                  }
                  
                  return MakeMap($modx, $siteMapRoot, 0, $showDescription, $titleOfLinks, $maxLevels, false, $pre, $post, $selfAsLink, $ie, $activeLinkIDs);
                  • Also, in regards to...’

                    The current page is the Courses which is "a.class=current", if i drop that, it no longer highlights the current page.

                    I did not mean you should remove the class from the A elements, just that the selector to access the sub UL’s should not include that reference - e.g. the sub UL was not a subelement of the A element, but the containing LI element (or UL); I had meant for you to adopt sottwell’s modification, and then reference it as
                    li.yourActiveClass ul
                    separate from the selector for your link styles
                    li a.yourActiveClass
                    • I needed a class for both the active li and the active a in order to have containers for two background images (see http://www.alistapart.com/articles/slidingdoors/ ). This purpose was so the fonts can be enlarged by the user; I use plain text in the menu with overlapping background images for each button to make nice rounded tabs. Four images, two for inactive and two for active links, are all that’s needed, no matter how many links you have.

                      Anyway, you should use the active li element to manage your dropdowns. (in the modified ListMenuX you specify the class names as arguments when you call the snippet) Check out http://www.alistapart.com/articles/dropdowns/, also the positioniseverything link I posted earlier.

                      You can put the descendent ul sections INSIDE the anchor tags, (<a href="#">Drop This<ul><li>blah</li></ul></a>) thus eliminating the need for javascript to make rollover dropdowns work in IE, since it’s the a:hover ul that we’re looking at; of course it’s not XHTML, but it does work.
                        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