3

I'm currently using the default calendar views "Upcoming" block to display upcoming events on my homepage. However, because events are infrequent, its common for there to be no upcoming events. In which case, the block disappears and leaves a big blank spot in the home page.

Is there way to show either the next four events OR the last four events? For example, if there is only one upcoming event, it would add the last three events to the list and display all four in ascending order.

Thanks!

2
  • create another block for next four events OR the last four events, and in your tpl check if the upcoming events is empty then display the other block.
    – user17543
    May 21, 2013 at 4:21
  • For the latest four events, is there a way to show them in increasing order (earliest first), and also the last four events. Seems like if its earliest first, you can only get the first four events. Or if you want the last four events, you have to have in the reverse order (newest first). May 22, 2013 at 14:56

1 Answer 1

0

FYI, here is how I solved it. Thanks Rock, for the step in the right direction!

Overview: Used a custom module that creates a block that displays one of two view displays.

  1. Programmatically created a view (hook_views_api, hook_views_default_views) with two displays: one that shows upcoming events (ascending order, up to 4 items without a pager), and one that shows the last four events in the database (descending order, 4 items without a pager)

  2. Programmatically created a block (hook_block_info) that displays (hook_block_view) one of the two view displays based on the number of results in the "Upcoming" display ( $results = views_get_view_result('view_id', 'display_id');).

  3. Created a custom template file (views-view-unformatted--view-id--display-id.tpl.php) for the second display, which reverses the order of results so that they are still displayed with earliest date first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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