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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

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

Tutorial 2: Ordering the news and number of displayed items


Go to End


3 Posts   1893 Views

Avatar
thrax

Community Member, 32 Posts

15 August 2008 at 3:32pm

Hi guys,

Maybe I've been awake too long staring at this screen but I swear I cannot see anywhere in Tutorial 2 that shows how to order the news posts!

The problem I have: Using the news post setup (exactly as show in tutorial 2), whenever I create a new ArticlePage it orders itself (in the CMS and on the news page) under the previous posts... how do I get them to run in order from most recently posted to oldest?

Also... is there a way (already documented preferably) to show say.. the last 10 news items only, and have the rest off the page in record sets (im not sure if thats the right terminology sorry), eg: small number at the bottom of them page where you can go back and see previously posted news.

Thanks in advance....

Avatar
Willr

Forum Moderator, 5523 Posts

15 August 2008 at 5:03pm

I think it shows this code in the tutorial

DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num).

Which translates to

GET ALL of the 'ArticlePages' whose Parent = X. Order it by the Date Desc. And $num is the limit of how much you want to limit it to. If you want all the pages you can just get rid of the last parameter - this will get all. If you make $num 10 then it will get the latest 10.

So the format in SQL terms is

DataObject::get( <TYPE OF PAGE>, <FILTER>, <SORT OPTION>, <JOIN OPTION>, <LIMIT>);

Join is more compilcated so you can leave it blank. See http://doc.silverstripe.com/doku.php?id=datamodel&s=dataobject

Avatar
thrax

Community Member, 32 Posts

15 August 2008 at 5:26pm

Thanks mate, got it sorted now with your help!