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   1025 Views

Avatar
mrjohnson

12 April 2012 at 1:36am Community Member, 4 Posts

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

13 April 2012 at 7:16pm Forum Moderator, 5511 Posts

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

13 April 2012 at 10:27pm (Last edited: 13 April 2012 10:37pm), Community Member, 4 Posts

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

14 July 2012 at 1:57am Community Member, 4 Posts

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

I am happy to pay someone for support.

Avatar
boombox

6 September 2012 at 2:18am Community Member, 44 Posts

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

7 September 2012 at 9:54pm Forum Moderator, 5511 Posts

@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

7 September 2012 at 11:46pm Community Member, 44 Posts

@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

27 October 2012 at 4:26pm (Last edited: 27 October 2012 4:28pm), Community Member, 44 Posts

<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