
Any code? How did you call the snippet?
[[!BasicNav &sortBy=`menuindex` &sortDir=`ASC`]]
That’s really awkward.
I’m really happy people are using this. All working well?
<?php
/* BasicNav by Nimja.com
(enhanced a little bit by michael-van-laar.de)
Snippet call (example with all optional parameters):
[[!BasicNav? &sortBy=`publishedon` &sortDir=`ASC` ¤tPosition=`[[*id]]` &placeholder=`0` &hideFirst=`0`
&hidePrev=`0` &hideNext=`0` &hideLast=`0` &firstTxt=`<<` &prevTxt=`<` &nextTxt=`>` &lastTxt=`>>`]]
Placeholder (if &placeholder=`1` is used in the snippet call):
[[!+basicnav]]
Snippet call and placeholder MUST be called uncached, otherwise pages in the middle would not know when a new last page is added.
Parameters (all optional) in detail :
&sortBy Field containing the sorting order criterion Default: publishedon
&sortDir Sorting order (ASC or DESC) Default: ASC
¤tPosition ID of the resource which marks the current position Default: (ID of current resource)
in the page tree level you want to get the next and
previous resource from.
YOU ONLY NEED THIS PARAMETER IF YOU WANT TO "BREAK
OUT" OF THE CURRENT FOLDER.
Example:
In the following resource structure (page tree) you want to include links
to the next and previous project on every "project detail" page.
In this case you have to set ¤tPosition to [[*parent]]. By doing this
the next and previous links on every "project detail" page don't refer to
the next and previous "project detail" page (as they normally would), but to
the next and previous "project" page.
+ Project overview
|
+--+ Project 1
| +--- Project detail page 1.1
| +--- Project detail page 1.2
|
+--+ Project 2
| +--- Project detail page 2.1
| +--- Project detail page 2.2
|
+--+ Project 3
+--- Project detail page 3.1
+--- Project detail page 3.2
In concrete terms:
Placing the snippet and placeholder call
[[!BasicNav? ¤tPosition=`[[*parent]]`]] [[!+basicnav]]
on page "Project detail page 2.1" would generate one link to page
"Project 1" and one link to page "Project 3".
&placeholder Output is stored in placeholder (see above) Default: 0 (= FALSE)
&hideFirst "First link" will never be displayed. (Useful if Default: 0 (= FALSE)
only next and previous links should be displayed.)
&hidePrev "Previous link" will never be displayed. (Useful if Default: 0 (= FALSE)
only first and last links should be displayed.)
&hideNext "Next link" will never be displayed. (Useful if Default: 0 (= FALSE)
only first and last links should be displayed.)
&hideLast "Last link" will never be displayed. (Useful if Default: 0 (= FALSE)
only next and previous links should be displayed.)
&firstTxt Link text of "first link" Default: <<
&prevTxt Link text of "previous link" Default: <
&nextTxt Link text of "next link" Default: >
&lastTxt Link text of "last link" Default: >>
*/
// ---- Default Values forced.
$sortBy = !empty($sortBy) ? $sortBy : 'publishedon';
$sortDir = !empty($sortDir) ? $sortDir : 'ASC';
$placeholder = !empty($placeholder) ? $placeholder : FALSE;
$cur = !empty($currentPosition) ? $currentPosition : $modx->resource->id;
$hideFirst = !empty($hideFirst) ? $hideFirst : FALSE;
$hidePrev = !empty($hidePrev) ? $hidePrev : FALSE;
$hideNext = !empty($hideNext) ? $hideNext : FALSE;
$hideLast = !empty($hideLast) ? $hideLast : FALSE;
$firstTxt = !empty($firstTxt) ? $firstTxt : '<<';
$prevTxt = !empty($prevTxt) ? $prevTxt : '<';
$nextTxt = !empty($nextTxt) ? $nextTxt : '>';
$lastTxt = !empty($lastTxt) ? $lastTxt : '>>';
// ---- Actual code
//Get the parents (and verify)
$curResource = $modx->getObject('modResource',$cur);
$parent = $curResource->get('parent');
if (empty($parent)) {
return 'No parent?';
exit;
}
//Get the children.
$criteria = $modx->newQuery('modResource');
$criteria->where(array(
'parent' => $parent,
'hidemenu' => 0,
));
$criteria->sortby($sortBy,$sortDir);
$children = $modx->getCollection('modResource',$criteria);
$first = NULL;
$prev = NULL;
$next = NULL;
$last = NULL;
$seen = FALSE;
$now = FALSE;
foreach ($children as &$child) {
//Check if this is the current child.
$now = ($child->id == $cur);
if ($now) $seen = TRUE;
//First one is only set once.
if (!$hideFirst && !$seen && empty($first)) $first = $child;
//Prev is set until we meet our current.
if (!$hidePrev && !$seen) $prev = $child;
//Next is set once directly after the current.
if (!$hideNext && $seen && empty($next) && !$now) $next = $child;
//Set after we've seen stuff.
if (!$hideLast && $seen && !$now) $last = $child;
}
//Disable certain things at times.
if (!$hideFirst && ($first == $prev)) $first = NULL;
if (!$hideLast && ($last == $next)) $last = NULL;
$result = '<div class="nav">';
if (!$hideFirst) $result .= empty($first) ? '<div></div>' : '<div><a href="[[~'.$first->id.']]" class="first" title="'.$first->pagetitle.'">'.$firstTxt.'</a></div>';
if (!$hidePrev) $result .= empty($prev) ? '<div></div>' : '<div><a href="[[~'.$prev->id.']]" class="prev" title="'.$prev->pagetitle.'">'.$prevTxt.'</a></div>';
if (!$hideNext) $result .= empty($next) ? '<div></div>' : '<div><a href="[[~'.$next->id.']]" class="next" title="'.$next->pagetitle.'">'.$nextTxt.'</a></div>';
if (!$hideLast) $result .= empty($last) ? '<div></div>' : '<div><a href="[[~'.$last->id.']]" class="last" title="'.$last->pagetitle.'">'.$lastTxt.'</a></div>';
$result .= '</div>';
if ($placeholder) {
$modx->setPlaceholder('basicnav', $result);
return;
} else {
return $result;
}
thanks!