|
[[!siblingNav? &parents=`4` &limit=`4` &sortBy=`{"publishedon":"DESC"}` &prevTpl=`mxt.prevTpl` &nextTpl=`mxt.nextTpl`]] |
|
|
|
<ul class="clearfix">[[+sn.prev]][[-+sn.prevlinks]][[-+sn.nextlinks]][[+sn.next]]</ul> |
|
|
|
|
|
PREV |
|
|
|
<li>[[+_isactive:is=`1`:then=`<a href="[[~[[+id]]]]">« [[+pagetitle]]</a>`:else=` « `]]</li> |
|
|
|
////// |
|
|
|
/* |
|
* Wayne Roddy (wayne@modx.com) |
|
* Dec 1 2016 |
|
* Snippet for retrieving children with a {Specific} Template |
|
* Creating an Array and finding the siblings for Placeholders |
|
* Used on the News Item Page |
|
* |
|
* [[GetSiblingstoPH? &tpl=`15`]] |
|
*/ |
|
|
|
$siblings = []; |
|
|
|
$activeId = $modx->resource->get('id'); |
|
$parentId = $modx->resource->get('parent'); |
|
$tpl = $modx->getOption('tpl', $scriptProperties); |
|
|
|
$q = $modx->newQuery('modResource'); |
|
$q->where(array('published'=>'1','parent'=>$parentId,'template'=>$tpl,'class_key'=>'modDocument')); |
|
$q->sortby('publishedon','DESC'); |
|
$resources = $modx->getCollection('modResource',$q); |
|
|
|
foreach($resources as $r) { |
|
$id = $r->get('id'); |
|
$title = $r->get('pagetitle'); |
|
|
|
$s = array("id" => $id,"title" => $title); |
|
|
|
array_push($siblings, $s); |
|
} |
|
|
|
//print_r($siblings); |
|
|
|
function activeKey($data, $field, $value){ |
|
foreach($data as $key => $item){ |
|
if ( $item[$field] === $value ) |
|
return $key; |
|
} |
|
return false; |
|
} |
|
$active_key = activeKey($siblings,'id',$activeId); |
|
|
|
//make previous html |
|
$prevkey = $active_key - 1; |
|
//$modx->log(modX::LOG_LEVEL_ERROR,'previous key: ' . $prevkey); |
|
if($prevkey >= 0){ |
|
$prevurl = $modx->makeUrl($siblings[$prevkey]["id"]); |
|
$prevChunk = $modx->getChunk("sibling-prev", array("url"=>$prevurl,"title"=>$siblings[$prevkey]["title"])); |
|
} else { |
|
$prevChunk = $modx->getChunk("sibling-empty", array()); |
|
} |
|
|
|
//make next html |
|
$nextkey = $active_key + 1; |
|
//$modx->log(modX::LOG_LEVEL_ERROR,'next key: ' . $nextkey); |
|
if($nextkey < count($siblings)){ |
|
$nexturl = $modx->makeUrl($siblings[$nextkey]["id"]); |
|
$nextChunk = $modx->getChunk("sibling-next", array("url"=>$nexturl,"title"=>$siblings[$nextkey]["title"])); |
|
} else { |
|
$nextChunk = $modx->getChunk("sibling-empty", array()); |
|
} |
|
|
|
$modx->setPlaceholders(array('Next' => $nextChunk),'sibling.'); |
|
$modx->setPlaceholders(array('Prev' => $prevChunk),'sibling.'); |
what was the issue you were having with this @dubrod?