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.

All other Modules

Discuss all other Modules here.

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

Event Calendar - Past Events


Reply

5 Posts   1130 Views

Avatar
bod

13 April 2010 at 7:47am (Last edited: 13 April 2010 7:51am), Community Member, 72 Posts

Hi, Does anyone know how to show past events from the Event Calendar?

I know there's the upcomingEvent function but is there a past/previous event function? I want to show a list of past event teasers on the homepage, yesterday and back - my current code

    function Events() {
       $today = date("Y-m-d");
       return DataObject::get_one("Calendar")->Events(null, $today, null, false, 5, null);
       }


just shows all upcoming events and trying something like

<% control PreviousEvents %>
$Event.Title $_Dates $Event.Link, etc..
<% end_control %>

gives no joy either,

..any ideas?

Avatar
UncleCheese

13 April 2010 at 8:32am 4085 Posts

I believe the function RecentEvents() is decorated into your SiteTree.

Avatar
bod

13 April 2010 at 9:08am Community Member, 72 Posts

No joy with

    function RecentEvents() {
       $today = date("Y-m-d");
       return DataObject::get_one("Calendar")->RecentEvents(null, $today, null, false, 5, null);
       }


and this in the .ss file

<% if RecentEvents %>
   
      <% control RecentEvents %>
         <dl class="diary-events">
<dt>$_Dates</dt>
<dd><h4 class="summary"><% if Announcement %><a href="$Link">$RecentEventsTitle</a><% else %><a href="$Link">$RecentEventsTitle</a><% end_if %></h4>
         
<% if Announcement %>
$Content
<% else %>
<% control RecentEvents %>$Content.LimitWordCount(60)<% end_control %> <a href="$Link"><% _t('MORE','more...') %></a>
<% end_if %>
<br />
<% if Announcement %><a href="$Link">Read More&#8230;</a><% else %><a href="$Link">Read More&#8230;</a><% end_if %>
      </dd>
</dl>   
      <% end_control %>

Sent you an email over the weekend so best wait till I hear back from you re: this with the other stuff.

Avatar
UncleCheese

13 April 2010 at 9:16am 4085 Posts

Oh, this is Adam? Hey, there.. Will get back to you tonight.

You shouldn't have to write a function. The RecentEvents() function is decorated on your SiteTree class, just like UpcomingEvents. The first argument is the number of events to show (default is 5), and the second is a url-segment to the calendar you want to draw from. If null, it gets the first Calendar it finds in the DB. For sites with one calendar, you can usually just leave those both empty.

So delete any functions you've written, and just let the core function do its thing. You should be able to call <% control RecentEvents %> on any SiteTree subclass.

Avatar
bod

13 April 2010 at 9:43am Community Member, 72 Posts

:o) Yep tis me, UC, had a footle with that but my mojo is obviously not working tonight, no worries, catch up with you later ;o) ta!