Created
August 18, 2016 09:36
-
-
Save ig0r74/4bf003c23ac4a79de09ed2fe54815413 to your computer and use it in GitHub Desktop.
Предыдущая и следующая новость в Smarty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{$params = [ | |
'currid' => {$modx->resource->id} | |
]} | |
{processor action="web/prevnext/getdata" params=$params ns=modxsite assign=result} | |
{$pn=$result.object} | |
<div class="row"> | |
<div class="col-md-4 text-center"> | |
{if $pn.prev} | |
<a href="{$pn.prev.uri}">← Предыдущая новость</a> | |
{/if} | |
</div> | |
<div class="col-md-4 text-center"><a href="[[~5]]">Читать все новости ↑</a></div> | |
<div class="col-md-4 text-center"> | |
{if $pn.next} | |
<a href="{$pn.next.uri}">Следующая новость →</a> | |
{/if} | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__ . '/../resources/getdata.class.php'; | |
class modWebPrevNextGetdataProcessor extends modWebResourcesGetdataProcessor{ | |
public function initialize(){ | |
$this->setDefaultProperties(array( | |
'includeTVs' => false, | |
'sort' => "{$this->classKey}.publishedon", | |
'dir' => 'desc', | |
'showhidden' => true, | |
'showunpublished' => false, | |
'limit' => 0, | |
'parent' => 5, | |
# 'currid' => null, | |
)); | |
return parent::initialize(); | |
} | |
public function afterIteration(array $list){ | |
$items = parent::afterIteration($list); | |
$items=array_values($list); | |
$prev=-1; | |
$next=0; | |
$curr=$this->getProperty('currid'); | |
for($i=0;$i<count($items);$i++){ | |
// print $items[$i]['id']."\n"; | |
if($items[$i]['id']==$curr){ | |
$prev=$i-1; | |
$next=$i+1; | |
break; | |
} | |
} | |
$prev=($prev>=0)?$items[$prev]:null; | |
$next=($next>0 && $next<count($items))?$items[$next]:null; | |
return ['prev'=>$prev,'next'=>$next]; | |
} | |
} | |
return 'modWebPrevNextGetdataProcessor'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment