[SOLVED] RSS2HTML how to sort

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

[SOLVED] RSS2HTML how to sort

Post 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!
Last edited by blackhawk on Mon Jun 02, 2014 5:30 am, edited 1 time in total.
clj83
Forum Members
Forum Members
Posts: 195
Joined: Tue Jul 07, 2009 4:09 pm

Re: RSS2HTML how to sort

Post 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}
blackhawk
Power Poster
Power Poster
Posts: 280
Joined: Mon Oct 20, 2008 6:07 pm

Re: RSS2HTML how to sort

Post 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!
Post Reply

Return to “Modules/Add-Ons”