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.

Blog Module /

Discuss the Blog Module.

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

Latest articles first in Blog & Articles


Reply


8 Posts   1085 Views

Avatar
mrjohnson

Community Member, 4 Posts

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

Avatar
Willr

Forum Moderator, 5513 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");

Avatar
mrjohnson

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

Avatar
mrjohnson

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.

Avatar
boombox

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');
            $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 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) %>

Avatar
Willr

Forum Moderator, 5513 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.

Avatar
boombox

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 RSSWidget.ss to the following set but this is not limiting the result?

<% control FeedItems(5) %>

Cheers
Boombox

Avatar
boombox

Community Member, 44 Posts

27 October 2012 at 4:26pm

Edited: 27/10/2012 4:28pm

<SOLVED>
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