Usually I do test it better, but this was rather rushed. Birthday and stuff.[[!basicNav? &sortBy=`menuindex` &sortDir=`ASC`]]
just tried this snippet, but i’m not getting anything output with the following call:
[[!basicNav? &sortBy=`menuindex` &sortDir=`ASC`]]
same blank output if I try just [[!basicNav?]]
Anyone know what’s I’m doing wrong?
[[!BasicNav? &sortBy=`menuindex` &sortDir=`ASC`]]
einsteinsboi: tried that first. then switched to basicNav (camelcase like getResources). nothing with either. just tried it like BasicNav again. Still nothing.
[[!BasicNav? &sortBy=`menuindex` &sortDir=`ASC` &placeholder=`1`]]
[[!BasicNav? &sortBy=`menuindex` &sortDir=`ASC` &placeholder=`1`]][[!+basicnav]]
<div class="nav"><div></div><div><a title="Entry to Purgatory" class="prev" href="exhibitions/nicholas-frennette/entry-to-purgatory.html">></a></div><div><a title="Pimples Pickings" class="next" href="exhibitions/nicholas-frennette/pimples-pickings.html"><</a></div><div><a title="Sunday Afternoon In The Cornfeild" class="last" href="exhibitions/nicholas-frennette/39.html">>></a></div></div>
&showHidden If true, will show Resources regardless if Default: 0
they are hidden from the menus.
&outerClass Class to be applied to the outer div Default: nav
<?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".
&showHidden If true, will show Resources regardless if Default: 0
they are hidden from the menus.
&outerClass Class to be applied to the outer div Default: nav
&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;
$showHidden = !empty($showHidden) ? $showHidden : 0;
$outerClass = !empty($outerClass) ? $outerClass : 'nav';
$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' => $showHidden,
));
$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="'.$outerClass.'">';
if (!$hideFirst) $result .= empty($first) ? '' : '<div><a href="[[~'.$first->id.']]" class="first" title="'.$first->pagetitle.'">'.$firstTxt.'</a></div>';
if (!$hidePrev) $result .= empty($prev) ? '' : '<div><a href="[[~'.$prev->id.']]" class="prev" title="'.$prev->pagetitle.'">'.$prevTxt.'</a></div>';
if (!$hideNext) $result .= empty($next) ? '' : '<div><a href="[[~'.$next->id.']]" class="next" title="'.$next->pagetitle.'">'.$nextTxt.'</a></div>';
if (!$hideLast) $result .= empty($last) ? '' : '<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;
}
?>