List of Events from CiviCRM


/ Published in: HTML
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function cmp_date($a,$b) {
  4. if ($a['start_date'] > $b['start_date']) return 1;
  5. if ($a['start_date'] < $b['start_date']) return -1;
  6. return 0;
  7. }
  8.  
  9. if (module_exists('civicrm')) {
  10. civicrm_initialize(TRUE);
  11. require_once 'api/v2/Event.php';
  12. $params = array ();
  13. $myEvents = civicrm_event_search( $params );
  14. if ($myEvents) {
  15. $count = 0;
  16. $last = '';
  17. usort($myEvents,'cmp_date');
  18. foreach ($myEvents as $event) {
  19. $now = date('Y-m-d H:i:s');
  20. if ($now > $event['start_date']) continue;
  21. $startdate = date('D M j Y',strtotime($event['start_date']));
  22. $enddate = date('D M j Y',strtotime($event['end_date']));
  23.  
  24. $eventid = $event['id'];
  25. list($title_place, $title_desc) = split(":",$event['title'],2);
  26. if ($last != $startdate) {
  27. $display = '<br /><b>'.$startdate.'</b><br />';
  28. }
  29. $display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />';
  30. echo $display;
  31. $count++;
  32. $last = $startdate;
  33. if ($count > 8) break;
  34. // this limits the number of events to 8 - put in whatever number suits you
  35. }
  36. if ($count > 0) {
  37.  
  38. } else {
  39. echo 'No events found.';
  40. }
  41. } else {
  42. echo 'No events found.';
  43. }
  44. }
  45. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.