Quote from: security at Apr 14, 2008, 07:50 AM
Ну у Samz-a всегда много страниц, у меня больше 2000 не бывает. Галка показывать в меню стоит только у тех страниц которые показываются в основном меню и мне бы никогда не пришло в голову запихнуть туда все 2000. Причина банальна - из-за гугля. А там где галка показывать в меню не стоит вызываю так:
[[Wayfinder?startId=`[*id*]` &outerClass=`topnav` &ignoreHidden=`TRUE` &level=`1`]] или через ditto с фильтрацией по нужному тегу.
В итоге страницы не перегружены ссылками и нет скрытого текста. В такой ситуации когда оч много страниц вероятно лучше использовать параметрический поиск вместо 4000 ссылок, но тут мнение может быть у каждого свое.
гугль может быть отключен по rel="nofollow".
при таком вызове у тебя покажутся только дети документа [*id*], но не будет видно родителей.
Я нашел две ошибки в моем патче.
1. Оказывается корень сайта(id=0) не складывается в массив getParentIds. Соответственно [[Wayfinder? &startId=`0` &hideSubMenus=`1`]] ничего не выведет.
2. Потерялся учет параметра level. т.е. конструкция [[Wayfinder? &startId=`1` &level=`2` &hideSubMenus=`1`]] будет строить дерево по всем уровням начиная с 0.
Вот изменения к предыдущему патчу
1. Исправлены недочеты
2. Всегда показываются дети startId документа, даже если у текущего документа нету startId в родителях.
Index: assets/snippets/wayfinder/wayfinder.inc.php
===================================================================
--- assets/snippets/wayfinder/wayfinder.inc.php (revision 107)
+++ assets/snippets/wayfinder/wayfinder.inc.php (revision 117)
@@ -308,9 +308,29 @@
$ids = $modx->getChildIds($this->_config['id'],$this->_config['level']);
} else { // then hideSubMenus is checked, we don`t need all children
- $parents = $this->parentTree;
- //remove parents higher than startId
- $parents = array_diff($parents, $modx->getParentIds($this->_config['id']));
- foreach($parents as $p)
- $ids = $modx->getChildIds($p, 1, $ids);
+ // first we always included the chilren of startId document
+ // this fix problem with site root chidrens,
+ // because site root not included in $modx->getParentIds
+ $ids = $modx->getChildIds($this->_config['id'], 1, $ids);
+
+ $parents = array($modx->documentIdentifier);
+ $parents += $modx->getParentIds($modx->documentIdentifier);
+
+ // if startId not in parents, only show children of startId
+ if ($this->_config['id'] == 0 || in_array($this->_config['id'], $parents)){
+
+ //remove parents higher than startId(including startId)
+ $startId_parents = array($this->_config['id']);
+ $startId_parents += $modx->getParentIds($this->_config['id']);
+ $parents = array_diff($parents, $startId_parents);
+
+ //remove parents lower than level of startId + level depth
+ $level = $this->_config['level'];
+ if ($level == 0)
+ $level = 10; // constant getted from getParentIds function
+ $parents = array_slice(array_reverse($parents), 0, $level-1);
+
+ foreach($parents as $p)
+ $ids = $modx->getChildIds($p, 1, $ids);
+ }
}
патч к оригиналу
Index: assets/snippets/wayfinder/wayfinder.inc.php
===================================================================
--- assets/snippets/wayfinder/wayfinder.inc.php (revision 70)
+++ assets/snippets/wayfinder/wayfinder.inc.php (revision 117)
@@ -305,5 +305,34 @@
global $modx;
$ids = array();
- $ids = $modx->getChildIds($this->_config['id'],$this->_config['level']);
+ if (!$this->_config['hideSubMenus']) {
+ $ids = $modx->getChildIds($this->_config['id'],$this->_config['level']);
+ } else { // then hideSubMenus is checked, we don`t need all children
+ // first we always included the chilren of startId document
+ // this fix problem with site root chidrens,
+ // because site root not included in $modx->getParentIds
+ $ids = $modx->getChildIds($this->_config['id'], 1, $ids);
+
+ $parents = array($modx->documentIdentifier);
+ $parents += $modx->getParentIds($modx->documentIdentifier);
+
+ // if startId not in parents, only show children of startId
+ if ($this->_config['id'] == 0 || in_array($this->_config['id'], $parents)){
+
+ //remove parents higher than startId(including startId)
+ $startId_parents = array($this->_config['id']);
+ $startId_parents += $modx->getParentIds($this->_config['id']);
+ $parents = array_diff($parents, $startId_parents);
+
+ //remove parents lower than level of startId + level depth
+ $level = $this->_config['level'];
+ if ($level == 0)
+ $level = 10; // constant getted from getParentIds function
+ $parents = array_slice(array_reverse($parents), 0, $level-1);
+
+ foreach($parents as $p)
+ $ids = $modx->getChildIds($p, 1, $ids);
+ }
+
+ }
//Get all of the ids for processing
if ($this->_config['displayStart'] && $this->_config['id'] !== 0) {
Любые замечания приветствуются