2

I want to get all occurrences of a single calendar and sort them by the occurrence start date. The reason why I want to do this is because I want to create an occurrence details page. To do that I need the occurrence ID, the calendar:cal tag does not seem to give me the occurrence id when printing out a single occurrence. I have tried the calendar:occurrences tag, but I cannot get that one to sort the occurrences by occurence_start date. I have tried using the default orderby and sort options to accomplish the sorting, but to no avail.

How can I do this? What are my options?

  • have you tried orderby="event_start_date"? – nageeb Aug 16 '13 at 1:13
2

First, I highly recommend having a look at this documentation page explaining the differences between some of the more common Calendar tags. Always useful:

http://www.solspace.com/docs/calendar/getting_started/

In detail, if you're looking to create a chronological list of events/occurrences, use {exp:calendar:cal}. This is the only tag that will make the necessary calculations to list your occurrences in chronological order. Each occurrence will be listed chronologically, with {event_start_date} displaying the start date of each occurrence:

{exp:calendar:cal 
   date_range_start="1 month ago" 
   date_range_end="+1 month"
   pad_short_weeks="n"}
   {events}
       [{event_id}] {event_title} - {event_start_date format="%Y-%m-%d"}<br />
   {/events}
{/exp:calendar:cal}

Occurrences do not have their own occurrence_id unless the occurrence is edited in the Control Panel. By default the ID is the same as the "master" event_id set up in the "Calendar: Events" channel entry form.

To print out information about a single occurrence (for a specific day, for example), a good solution is to pass three elements in the URL:

  • The start date
  • The end date (if different from the start date)
  • The "master" event_id

For example, if you want to display occurrence data for 2013-08-19 (for master event "123"), make a URL like this:

http://mysite.com/calendar/event/2013/08/09/123 

...and use {exp:calendar:cal} to "zoom in" on that occurrence:

<h3>Occurrence details:</h3>
{exp:calendar:cal 
   date_range_start="{segment_3}-{segment_4}-{segment_5}" 
   date_range_end="{segment_3}-{segment_4}-{segment_5}"
   pad_short_weeks="n"
   event_id="{segment_6}"
}
   {events}
       {event_title} occurrence data:<br />
       Starts on  {event_start_date format="%Y-%m-%d"}<br />
       Ends on  {event_end_date format="%Y-%m-%d"}<br />
   {/events}
{/exp:calendar:cal}

Of course you can change the structure of the URL to be

http://mysite.com/calendar/event/2013-08-09/123

...and use {exp:calendar:cal} accordingly:

{exp:calendar:cal 
   date_range_start="{segment_3}" 
   date_range_end="{segment_3}"
   pad_short_weeks="n"
   event_id="{segment_4}"
}
// the rest of the code...
| improve this answer | |
  • I've found the above answer very helpful, thanks! But could you please expand on your comment about "making a URL like this"? I'd assume that in the main list of events, you'd link each list item with an HREF tag; then what would be the exact URL specifics in that tag to pass the date along? Thanks very much! – Jenny T. Oct 4 '13 at 16:20
  • This is not an answer to the question. If you have comments or clarification questions, please add them as comments to the question or answer they refer to. – Jeremy Gimbel Oct 4 '13 at 20:41
  • @JeremyGimbel Actually, that is an answer. The answer was that the wrong tag was being used to accomplish the OP's goal. Guess I could have worded it as "{exp:calendar:occurrences} isn't the optimal tag for creating a list of occurrences ordered by start date (chronological)". :) – Solspace Oct 7 '13 at 20:09
  • @JennyT. Creating a URL to point to your event detail page, using the structure suggested above, could be done in more than one way, but here's one example: <a href="{path='event/details'}/{event_start_date format="%Y/%m/%d"}/{event_id}">{event_title} details</a>. Of course, it all depends if you want to make the year, month and date separate segments or not in your URL. :) – Solspace Oct 7 '13 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.