0

I'm outputting occurrences using the {occurrences} variable pair within a {exp:calendar:events} tag for a single day and I'd like to sort these occurrences by time.

{exp:calendar:events calendar_id="22" date_range_start="2013-11-10" date_range_end="2013-11-10" sort="asc" show_years="9" pad_short_weeks="n"}

   {occurrences}
      {occurrence_start_date format="%D, %F %j %g:%i %a"}
   {/occurrences}

{/exp:calendar:events}

I tried using the sort parameter in the occurrences variable pair and but it didn't work. Any tips?

1

I actually just ran into a similar issue with Solspace Calendar. The add-on is written so that ordering in this way is not possible (it has a built-in ordering process). You can't even use the fixed_order= parameter.

In the end, I had to utilize Stash to first grab all the event occurrences and set them into a list, then grab that Stash list and sort using Stash.

So, after you install Stash, try this:

{exp:stash:set_list name="event_occurrences" parse_tags="yes"}
  {exp:calendar:events calendar_id="22" date_range_start="2013-11-10" date_range_end="2013-11-10" show_years="9" pad_short_weeks="n"}
    {occurrences}
      {stash:occurrence_title}{title}{/stash:occurrence_title}
      {stash:occurrence_start_date_hour}{occurrence_start_date format="%D, %F %j %g:%i %a"}{/stash:occurrence_start_date_hour}
      {stash:occurrence_time_sort}{occurrence_start_date format="%Y%m%d%H%i"}{/stash:occurrence_time_sort}
    {/occurrences}
  {/exp:calendar:events}
{/exp:stash:set_list}

Then use Stash to display them in order by sorting according to {stash:occurrence_time_sort}

{exp:stash:get_list name="event_occurrences" orderby="occurrence_time_sort" sort="desc"}
  <h1>{occurrence_title}</h1>
  <h2>{occurrence_start_date_hour}</h2>
{/exp:stash:get_list}
4
  • Looks like a very convoluted way of getting a chronological list of events, when a simple {exp:calendar:cal} tag would do the same job. My two cents. :)
    – Solspace
    Oct 24 '13 at 17:01
  • @Solspace, true. :) I had to use this for custom ordering of events (not occurrences). Forgot about the :cal tag. Oct 24 '13 at 17:34
  • @Solspace: I think that this is the only way to get events list with one occurrence where the events are grouped and not showed "double/triple" as when using cal tag. as I can see, there is no way for limit-per-event listing in Cal tag.
    – Davor Peic
    May 29 '14 at 13:23
  • @DavorPeic You could do it with {exp:calendar:cal} and some PHP, building an array to prune out "duplicates". Likely a Stash approach is also possible. The other advantage is that everything stays chronological, too.
    – Solspace
    May 30 '14 at 20:56
1

If you're looking to order occurrences chronologically, you should be using {exp:calendar:cal}. This is the only tag that will order occurrences in true chronological order. Details on why/how can be found here: http://www.solspace.com/docs/calendar/getting_started/

2
  • So would the proper form to output occurrences for a day and to have those occurrences ordered by start date: {exp:calendar:cal calendar_id="22" date_range_start="2013-11-10" date_range_end="2013-11-10" sort="asc" show_years="9" pad_short_weeks="n"} {events} {occurrences orderby="occurrence_start_date" sort="asc"} {occurrence_start_date format="%D, %F %j %g:%i %a"} {/occurrences} {/events} {/exp:calendar:cal} Oct 25 '13 at 13:40
  • Close. You don't need show_years="" if the timeframe is a specific day. Same for sort="": {exp:calendar:cal} is already chronological. Also, {occurrences}{/occurrences} (which doesn't accept parameters, btw) is not needed. It would be rather this: {exp:calendar:cal calendar_id="22" date_range_start="2013-11-10" date_range_end="2013-11-10" pad_short_weeks="n"} {events} {event_start_date format="%D, %F %j %g:%i %a"} {/events} {/exp:calendar:cal}
    – Solspace
    Oct 26 '13 at 1:30

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.