📜 ⬆️ ⬇️

output news grouped by date

Given: MODx 1.0.0
It is necessary: ​​to display a list of news in the following format:
25.08.09
> 2 25


> 1 25


24.08.09
> 24


Is it possible to do this without rewriting a piece of Ditto?

Option 1 - extender . Save the code in the file assets / snippets / ditto / extenders / dateGroup.extender.inc.php
<?php
global $dateSource, $dateFormat;
$dateSource = isset($dateSource) ? $dateSource : "createdon";
$placeholders['groupDate'] = array(array($dateSource, "*"), "getGroupDate", $dateSource);
$dateFormat = isset($dateFormat)? $dateFormat : '%d.%m.%y';

if (!function_exists("getGroupDate")) {
function getGroupDate($resource) {
static $date = '', $id = '';
global $dateSource, $dateFormat;
if ($date !== strftime('%d.%m.%y', $resource[$dateSource]) || $id == $resource['docid']) {
$id = $resource['id'];
$date = strftime('%d.%m.%y', $resource[$dateSource]);
return strftime($dateFormat, $resource[$dateSource]);
} else {
return false;
}
}
}
?>

Next: in the parameters of the ditto call we include PHx - '& phx = `1`', in the chunk that displays each news of their list (& tpl) we write something like the following:
[+groupDate:isnot=``:then=`<p class='news_date'>[+groupDate+]</p>`+]
<p class='news_item'>
<span class='title'><a href='[~[+id+]~]'>[+pagetitle+]</a></span>
[+introtext:isnot=``:then=`<br /><span class='description'>[+introtext+]</span>`+]
</p>

Option 2, without Ditto (suggested by fuzzy ) - modx.ru/blog/modx-adding-articles

')

Source: https://habr.com/ru/post/69342/


All Articles