We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13577
    • 302 Posts
    This is an auto-generated support/comment thread for ListSiteMap.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Creates a sitemap for your site, or any node of your site.
      Standard Disclaimer
      I could be totally wrong.
      • 661
      • 33 Posts
      This snippet is great! Sweet and to the point...

      I just have one question (of course!)... How can I prevent certain pages from displaying in the sitemap? For example, I have two pages (an error and an unauthorized) set up that I don’t want shown on the sitemap.

      Thanks!

        • 13577
        • 302 Posts
        Do those pages have the "show in menu" option UNchecked?

        The way I go about doing that is to put pages like that in an unpublished folder and then only use the site map such that it doesn’t go past the unpublished folders.
          Standard Disclaimer
          I could be totally wrong.
          • 661
          • 33 Posts
          Quote from: jaredc at Oct 09, 2006, 10:59 AM

          Do those pages have the "show in menu" option UNchecked?

          The way I go about doing that is to put pages like that in an unpublished folder and then only use the site map such that it doesn’t go past the unpublished folders.

          Unfortunately that won’t do - and I apologize for not including a more detailed explanation. The two pages I want to exclude from the sitemap are error and unauthorized pages, so they have to be published. I think I may try a work-around though... (light bulb just went off).
            • 25663 MODX Staff
            • 12,272 Posts
            Show in menu and published are two separate things.
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 7923
              • 4,213 Posts
              And the unpublished thing means that you do a unpublished folder and put the error and unauthorized documents inside it as published. They will still work, but not show up in sitemap.


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 13481
                • 97 Posts
                I’m not sure if this is the place to contribute code or not, but here is a version of the snippet that has a flag for showing/hiding items that are (un)checked as ’Show in Menu’:

                // --------------------
                // Snippet: ListSiteMap
                // --------------------
                // Version: 0.9.0
                // Date: 2006.08.14
                // [email protected]
                //
                // This snippet was designed to show a nested
                // list site map with each pagetitle being a
                // link to that page. It will not include
                // unpublished folders/pages OR its children,
                // even if the children ARE published.
                
                // Config
                   // $siteMapRoot [int]
                   // The parent ID of your root. Default 0. Can be set in 
                   // snippet call with LSM_root (to doc id 10 for example):
                   // [[ListSiteMap?LSM_root=10]]
                   $siteMapRoot = 0;
                
                   // $showDescription [ 1 | 0 ]
                   // Specify if you would like to include the description
                   // with the page title link.
                   $showDescription = 1;
                
                   // $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 [ 1 | 0 ]
                   // If you want new lines removed from code, set to true. This is generally
                   // better for IE when lists are styled vertically. 
                   $removeNewLines = 1;
                   
                   // $maxLevels [ int ]
                   // Maximum number of levels to include. The default 0 will allow all
                   // levels. Also settable with snippet variable LSM_levels:
                   // [[ListSiteMap?LSM_levels=2]]
                   $maxLevels = 0;
                   
                   // $selfAsLink [ true | false ]
                   // Define if the current page should be a link (true) or not
                   // (false)
                   $selfAsLink = 0;
                   
                   // $showUnpubs [ true | false ]
                   // Decide to include items in unpublished folders. This will show the
                   // unpublished items as well. No links will be made for the unpublished items
                   // but they will be shown in the structure. You will not likely want to do
                   // this but the option is yours.
                   $showUnpubs = 0;
                
                   // $showHideMenu [ true | false ]
                   // Decide to include menu items that are checked as hidden from the menu.    
                   // Hides all children of the hidden document as well.
                   $showHideMenu = 0;
                
                // Styles
                //
                // .LSM_currentPage    span surrounding current page if $selfAsLink is false
                // .LSM_description    description of page
                // .LSM_N              ul style where N is the level of nested list- starting at 0
                
                // ###########################################
                // End config, the rest takes care of itself #
                // ###########################################
                
                // Initialize
                $siteMapRoot = (isset($LSM_root))? $LSM_root : $siteMapRoot ;
                $maxLevels = (isset($LSM_levels))? $LSM_levels : $maxLevels ;
                $ie = ($removeNewLines)? '' : "\n" ;
                
                // Overcome single use limitation on functions
                
                if(!function_exists('MakeSiteMap')){
                  function MakeSiteMap($funcModx, $listParent, $listLevel, $description, $titleOfLinks,$maxLevels,$su,$selfAsLink,$shm){
                    $children = $funcModx->getAllChildren($listParent,'menuindex ASC, pagetitle','ASC','id,pagetitle,description,parent,alias,longtitle,published,deleted,hidemenu');
                    $output .= '<ul class="LSM_'.$listLevel.'">'.$ie;
                    foreach($children as $child){
                
                      // skip unpubs unless desired
                      if ((!$su && !$child['published']) || ($child['deleted']) || (!$shm && $child['hidemenu'])) continue;
                      
                      $descText = ($description)? ' <span class="LSM_description">'.$child['description'].'</span>' : '';
                      $output .= '<li>';
                      if ((!$selfAsLink) && ($child['id'] == $funcModx->documentIdentifier)){
                        $output .= '<span class="LSM_currentPage">'.$child['pagetitle'].'</span>';
                      } else if (!$child['published']){
                        $output .= '<span class="LSM_unpubPage">'.$child['pagetitle'].'</span>';
                      } else {
                        $output .= '<a href="[~'.$child['id'].'~]" title="'.$child[$titleOfLinks].'">'.$child['pagetitle'].'</a>';
                      }
                      $output .= $descText;
                      if ($funcModx->getAllChildren($child['id']) && (($maxLevels==0) || ($maxLevels > $listLevel+1 ))){
                        $output .= MakeSiteMap($funcModx,$child['id'],$listLevel+1,$description,$titleOfLinks,$maxLevels,$su,$selfAsLink,$shm);
                      }
                      $output .= '</li>'.$ie;
                    }
                    $output .= '</ul>'.$ie;
                    return $output;
                  }
                }
                
                return MakeSiteMap($modx, $siteMapRoot, 0, $showDescription, $titleOfLinks,$maxLevels,$showUnpubs,$selfAsLink,$showHideMenu);
                


                Pretty simple check to put in place.

                James
                  • 4643
                  • 34 Posts
                  Hi!
                  I’ve tried out the ListSiteMap - a good idea, something like this is very useful. I have few feature requests / comments...

                  First: The original ListSiteMap showed up my styles.css, some javascript.js etc but the above modification removed that problem (because they had "show in menu" unticked).

                  However, the modification above killed something else unfortunately. This is how one of my sites is organized:

                  index.html
                  english-pages-on-root-level.html
                  LANGUAGES (folder)
                  LANGUAGE1 (folder)
                  first-page in language1.html
                  ...
                  LANGUAGE2 (folder)

                  etcetera.

                  The LANGUAGES folder is there for internal reasons, it just makes the structure neater. That has "show in menu" unticked.
                  Each LANGUAGEn folder has "show in menu" ticked.

                  All folders are using FirstChildRedirect so no-one can actually view a folder, they will be redirected to the first "real" html page below.

                  The problem: With the modified code showing only pages ticked to be in the menu - all my LANGUAGEn folders and sub-documents disappears. With the original code, they are there but unfortunately also a lot of javascripts, sitemap.xml etcetera.

                  It appears that maybe the modified code assumes that everything below a non-show-in-menu file/folder can be excluded? Or maybe it’s a bug somehow. Anyway, ideally ALL files/folders marked as "show in menu" should be included in the sitemap if that is possible, regardless of the structure.

                    • 13481
                    • 97 Posts
                    Sorry I don’t have the time to look into your problem further. I did correct my typo in the comment (there should have been ’not’ in there - that makes a big difference smiley ). Anyway, you are correct that all children will be hidden if the parent is marked as hidden. I think that doing what you want to do would make the script more complicated than it is now since it creates a fuzzy logic as to what level the parent items are at (you’d be saying that the LANGUAGEx items should be a the root level when they are not). Sorry I don’t have a solution for you at the moment, but thanks for pointing these things out.

                    James
                      • 21800
                      • 174 Posts
                      The snippet works fine so far. But there is one thing equal to menu stuff: What to do if the parent topic i.e. the first doc level shall not be linked (for that pages are "folders")?