Page 1 of 1

[SOLVED] RSS2HTML how to sort

Posted: Sun Jun 01, 2014 12:56 pm
by blackhawk
with the RSS2HTML module that can be installed in CMSMS, how can we sort the items by date in either ascending or descending order as they are listed?

I am currently using the following code in CMSMS for this module...

Code: Select all

{foreach from=$rss->items item='item'}
<div class="rssbox">
<h3><a href="{$item.link}">{$item.title}</a></h3>
<em>
<time pubdate="{$item.pubdate|date_format:'%Y-%m-%d'}">{$item.pubdate}</time>
</em>
<p>{$item.summary}</p>
</div>
{/foreach}
thanks for any help!

Re: RSS2HTML how to sort

Posted: Sun Jun 01, 2014 2:04 pm
by clj83
You can create a UDT which uses the PHP date compare function and run this before your foreach loop.

UDT:

Code: Select all

function date_compare($a, $b)
{
    $t1 = strtotime($a->pubdate);
    $t2 = strtotime($b->pubdate);
    return $t2 - $t1;
}    
$data = $params['data'];
usort($data, 'date_compare');
$smarty->assign('sorted', $data);
Template:

Code: Select all

{postDateSort data=$rss->items}
{foreach from=$sorted item=node name=blog}
as before
{/foreach}

Re: RSS2HTML how to sort

Posted: Sun Jun 01, 2014 8:30 pm
by blackhawk
thank you so much.
I actually went to the source of this entire issue...I am pulling a feed from my Google Calendar into RSS2HTML. Tonight I discovered that you can sort the Google feed from the URL (with URL parameters), THEN load that entire URL feed into RSS2HTML. And that worked!

Thank you so much for the initial help!