1776 Posts in 498 Topics by 533 members
Blog Module
SilverStripe Forums » Blog Module » Latest articles first in Blog & Articles
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 699 Views |
-
Latest articles first in Blog & Articles

12 April 2012 at 1:36am
Hello
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.
Thanks
-
Re: Latest articles first in Blog & Articles

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");
-
Re: Latest articles first in Blog & Articles

13 April 2012 at 10:27pm Last edited: 13 April 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
-
Re: Latest articles first in Blog & Articles

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.
-
Re: Latest articles first in Blog & Articles

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');
$date->setValue($item->get_date());// Cast the Title
$title = new Text('Title');
$title->setValue($item->get_title());// Cast the Description
$description = new Text('Description');
$description->setValue($item->get_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 feedWhats 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 worke.g. <% control FeedItems(5) %>
-
Re: Latest articles first in Blog & Articles

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.
-
Re: Latest articles first in Blog & Articles

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 RSSWidget.ss to the following set but this is not limiting the result?<% control FeedItems(5) %>
Cheers
Boombox -
Re: Latest articles first in Blog & Articles

27 October 2012 at 4:26pm Last edited: 27 October 2012 4:28pm
<SOLVED>
I have solved how to limit the number of items being displayed from a feed using the RSS widgetIn 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 templateSo 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
| 699 Views | ||
|
Page:
1
|
Go to Top |



