Делаем карту сайта на MODx на ListSiteMap

 

Карту сайта делаем на базе сниппета ListSiteMap

Небольшое отличие от оригинального кода - мой вариант корректно отображает ссылки на внешние сайты.

1) Создаём новый чанк sitemap с содержимым:

  1. [!ListSiteMap?LSM_root=`10`!]



 LSM_root=`10` - указывет на папку с документами сайта , нашем случае ID папки - 10 .
 

 

2) Создаём новый сниппет с названием ListSiteMap , Содержимое можно взять здесь

 

  1.  
  2.  
  3. <?php
  4. // --------------------
  5. // Snippet: ListSiteMap
  6. // --------------------
  7. // Version: 0.9.7
  8. // Date: 2008.02.07 // jaredc@honeydewdesign.com
  9. //
  10. // This snippet was designed to show a nested
  11. // list site map with each pagetitle being a
  12. // link to that page. It will not include
  13. // unpublished folders/pages OR its children,
  14. // even if the children ARE published.
  15. // only when option is set to see the unpublished pages the unpub pages wil be shown (not as link)
  16. // Added bij Dimmy:
  17. // Option to select if pages / folders that are not in menu will be showed or not
  18.  
  19. // Config
  20. // $siteMapRoot [int]
  21. // The parent ID of your root. Default 0. Can be set in
  22. // snippet call with LSM_root (to doc id 10 for example):
  23. // [[ListSiteMap?LSM_root=10]]
  24. $siteMapRoot = 0;
  25.  
  26. // $showDescription [ 1 | 0 ]
  27. // Specify if you would like to include the description
  28. // with the page title link.
  29. $showDescription = 1;
  30.  
  31. // $titleOfLinks [ string ]
  32. // What database field do you want the title of your links to be?
  33. // The default is pagetitle because it is always a valid (not empty)
  34. // value, but if you prefer it can be any of the following:
  35. // id, pagetitle, description, parent, alias, longtitle
  36. $titleOfLinks = 'longtitle';
  37.  
  38. // $removeNewLines [ 1 | 0 ]
  39. // If you want new lines removed from code, set to true. This is generally
  40. // better for IE when lists are styled vertically.
  41. $removeNewLines = 1;
  42.  
  43. // $maxLevels [ int ]
  44. // Maximum number of levels to include. The default 0 will allow all
  45. // levels. Also settable with snippet variable LSM_levels:
  46. // ListSiteMap? LSM_levels=2
  47. $maxLevels = 0;
  48.  
  49. // $selfAsLink [ true | false ]
  50. // Define if the current page should be a link (true) or not
  51. // (false)
  52. $selfAsLink = 1;
  53.  
  54. // $showSelf [ true | false ]
  55. // Should this page, the sitemap page, be shown in the sitemap?
  56. // (Added in version 0.9.7)
  57. // (true)
  58. $showSelf = 1;
  59.  
  60. // $showUnpubs [ 1 | 0 ]
  61. // Decide to include items in unpublished folders. This will show the
  62. // unpublished items as well. No links will be made for the unpublished items
  63. // but they will be shown in the structure. You will not likely want to do
  64. // this but the option is yours.
  65. $showUnpubs = 0;
  66.  
  67. // $showNotInMenu [ 1 | 0 ]
  68. // Decide to include items that are not in menu. This will show the
  69. // items not in menu including there children items as well.
  70. $showNotInMenu = 1;
  71.  
  72. // Styles
  73. //
  74. // .LSM_currentPage span surrounding current page if $selfAsLink is false
  75. // .LSM_description description of page
  76. // .LSM_N ul style where N is the level of nested list- starting at 0
  77. // .LSM_unpubPage span surrounding Unpub page title
  78. // .LSM_unpubPageLI Class for the li surounding the Unpub page title
  79.  
  80. // ###########################################
  81. // End config, the rest takes care of itself #
  82. // ###########################################
  83.  
  84. // Initialize
  85. $siteMapRoot = (isset($LSM_root))? $LSM_root : $siteMapRoot ;
  86. $maxLevels = (isset($LSM_levels))? $LSM_levels : $maxLevels ;
  87. $ie = ($removeNewLines)? '' : "\n" ;
  88.  
  89. // Overcome single use limitation on functions
  90.  
  91. if(!function_exists('MakeSiteMap')){
  92. function MakeSiteMap($funcModx, $listParent, $listLevel, $description, $titleOfLinks,$maxLevels,$su,$selfAsLink){
  93. $children = $funcModx->getAllChildren($listParent,'menuindex ASC, pagetitle','ASC','id,type,pagetitle,description,parent,alias,longtitle,published,deleted,hidemenu,content');
  94. $output .= '<ul class="LSM_'.$listLevel.'">'.$ie;
  95. foreach($children as $child){
  96.  
  97. // skip unpubs unless desired
  98. if ((!$su && !$child['published']) || ($child['deleted']) || ($showNotInMenu && $child['hidemenu'])) continue;
  99.  
  100. $descText = ($description)? ' <span class="LSM_description">'.$child['description'].'</span>' : '';
  101. $output .= '';
  102. $this_line_skipped = false; // (0.9.7)
  103. if ((!$selfAsLink) && ($child['id'] == $funcModx->documentIdentifier)){
  104. // We've established that this is the page itself. Should we show it?
  105. if ($showSelf) { // (0.9.7)
  106. $output .= '<li> <span class="LSM_currentPage">'.$child['pagetitle'].'</span>';
  107. $this_line_skipped = true;
  108. }
  109. } else if (!$child['published']){
  110. $output .= '<li class="LSM_unpubLI"> <span class="LSM_unpubPage">'.$child['pagetitle'].'</span>';
  111. } else if ($child['type']=="reference") {
  112. $output .= '<li> <a href="'.$child['content'].'" title="'.$child[$titleOfLinks].'">'.$child['pagetitle'].'</a>';
  113. }
  114. else {
  115. $output .= '<li> <a href="[~'.$child['id'].'~]" title="'.$child[$titleOfLinks].'">'.$child['pagetitle'].'</a>';
  116.  
  117. }
  118.  
  119. // Post Processing on a line (page) (0.9.7)
  120. // --------------------------------
  121.  
  122. // We might have skipped a page, due to showSelf = false. So, post-processing on a page should be
  123. // skipped too in that case. (since version 0.9.7)
  124. if (!$this_line_skipped) { // (0.9.7)
  125. $output .= $descText;
  126. if ($funcModx->getAllChildren($child['id']) && (($maxLevels==0) || ($maxLevels > $listLevel+1 ))){
  127. $output .= MakeSiteMap($funcModx,$child['id'],$listLevel+1,$description,$titleOfLinks,$maxLevels,$su,$selfAsLink);
  128. }
  129. $output .= '</li>'.$ie;
  130. }
  131.  
  132. }
  133. $output .= '</ul>'.$ie;
  134. return $output;
  135. }
  136. }
  137.  
  138. return MakeSiteMap($modx, $siteMapRoot, 0, $showDescription, $titleOfLinks,$maxLevels,$showUnpubs,$selfAsLink);
  139. ?>
  140.  
Последнее изменение документа: 05 Ноябрь 2009
aryanatha
Posts: 1
Comment
Спасибо большое
Reply #1 on : Втр Июль 27, 2010, 01:05:04
Все сделал за 3 минуты, все работает :)
Вот бы всегда так )))

Write a comment

  • Required fields are marked with *.

If you have trouble reading the code, click on the code itself to generate a new random code.