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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

EventPage sorted by date - howto show only until today?


Reply


3 Posts   1481 Views

Avatar
patte

Community Member, 63 Posts

22 February 2011 at 5:00am

Hi,

I have a problem with sorting by date...perhaps someone can help me out?

I have a EventHolder and a EventPage

in EventHolder.php i am sorting AllChildren() by a Date field

   function SortedChildren(){
    $children = $this->AllChildren();   
    if( !$children )
    return null;
    $children->sort('Date', 'ASC');   
    return $children;
   }

in EventHolder.ss i list those EventPages

<% control SortedChildren %>
<h2><a href="$Link">$Date.Format(d.m.Y) - $Title</a></h2>
<p>$Content.FirstParagraph<a class="arrow" href="$Link">weiter</a></p>
<% end_control %>

Now i want only to show EventPages with future dates. Old events should no longer be listed wen they are in the past.

Any idea?

Thanks much!

patte

Avatar
Bruce B

Community Member, 145 Posts

23 February 2011 at 5:07pm

Patte,
Try this:

function AllFutureChildren() {
$littlechildren = DataObject::get("EventPage", "Date >= CURDATE()", "Date ASC", null, null);
return $littlechildren;
}

add it to page.php so its accessible from all pages on the site.

Avatar
patte

Community Member, 63 Posts

14 March 2011 at 11:30pm

Thanks Bruce B ;-)

Works like a charm.