Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Latest articles first in Blog & Articles

Go to End

8 Posts   1898 Views


Community Member, 4 Posts

12 April 2012 at 1:36am


I am having a problem blog articles and regular articles to show the latest article first.

It is showing the last first and latest at the bottom.

Can someone please advise what code I need to change to show the latest first.



Forum Moderator, 5523 Posts

13 April 2012 at 7:16pm

How are you showing the list of articles. You can pass the sort as the 3rd argument to DataObject

$articles = DataObject::get('BlogArtice', "", "Date DESC");


Community Member, 4 Posts

13 April 2012 at 10:27pm

Edited: 13/04/2012 10:37pm

I am editing the work of someone else so not very familiar with the system. I cannot find anything similar to the code above.

There is nothing like it in /mysite/code/BlogPage.php or BlogHolder.php

I can post code from a specific file if that would help


Community Member, 4 Posts

14 July 2012 at 1:57am

If someone can help with this I would be greatly appreciative.

I am happy to pay someone for support.


Community Member, 44 Posts

6 September 2012 at 2:18am

Hi Willr
I am using the RSS Widget to return an external RSS Feed - see code below
This is working fine except items bring back the latest articles at the top of the list - I want the oldest (upcoming) articles at the top of the list for the sourced feed items.

### Code in RSSWidget.php ###

line 77
if($items = $feed->get_items(0, $this->NumberOfItems, $this->NumberToShow)) {
foreach($items as $item) {

// Cast the Date
$date = new Date('Date');

// Cast the Title
$title = new Text('Title');

// Cast the Description
$description = new Text('Description');

// store the item in our array we set up.
$output->push(new ArrayData(array(
'Title' => $title,
'Date' => $date,
'Description' => $description,
'Link' => $item->get_link()

$output -> sort("Date", "ASC");

return $output;



This is returning the number of items (set in widget config) to 5 items
But the actual number of items in the feed is approx 50 so even if I change the code to $output -> sort("Date", "DESC"); it just changes the order of the 5 items presented and not the order of the toatl 50 items in the RSS feed

Whats the best way to approach this?
I tried
- returning the number of items (set in widget config) to 50 items
- limiting in the template the number of items displayed (hack) but this doesn't work

e.g. <% control FeedItems(5) %>


Forum Moderator, 5523 Posts

7 September 2012 at 9:54pm

@boombox - most rss feeds return the latest at the top, the only way you can get the oldest is to set the number to get to max length of the rss feed (say 50) then do the sort as you have.


Community Member, 44 Posts

7 September 2012 at 11:46pm

@Willr - yes thanks have tried that and getting the order of the latest first
- however how do I limit the template output to say only the latest 5 results?
I have tried limiting the to the following set but this is not limiting the result?

<% control FeedItems(5) %>



Community Member, 44 Posts

27 October 2012 at 4:26pm

Edited: 27/10/2012 4:28pm

I have solved how to limit the number of items being displayed from a feed using the RSS widget

In RSSWidget.php (attached) I have
- added in a NumberofItems variable - this is used to set the number of items aggregated from the feed source
- used the NumberToShow variable to set how many is actually output on the template

So by aggregating all the feed items (or max number, then ordering by ascending to display the upcoming ones at top of the feed output and then controlling the actual number display in the template I can now have the upcoming items by date displayed first) - useful for event based rss feeds

In the function FeedItems I have added the following code from line 98

$output -> sort("Date", "ASC");
$limitoutput = $output->getRange(0, $this->NumberToShow);
return $limitoutput;

Happy Feeding :-)

Attached Files