I am using WordPress 3.3.2. and civiCRM plugin Version 4.1.3. I am trying to list all the active events in a page and from there I want to take the users to the respective pages. Right now i have one page per event and also that page becomes blank once you register the event.
Can you please tell me how to get the event listed and from there take them to individual events for registration. I want the event page to show up wether customers are registered or now.
I got this code from the web but dont know where to put it. I dont know whether this code will work or not either.
<?php
function cmp_date($a,$b) {
if ($a['start_date'] > $b['start_date']) return 1;
if ($a['start_date'] < $b['start_date']) return -1;
return 0;
}
if (module_exists('civicrm')) {
civicrm_initialize(TRUE);
require_once 'api/v2/Event.php';
$params = array ();
$myEvents = civicrm_event_search( $params );
if ($myEvents) {
$count = 0;
$last = '';
usort($myEvents,'cmp_date');
foreach ($myEvents as $event) {
$now = date('Y-m-d H:i:s');
if ($now > $event['start_date']) continue;
$startdate = date('D M j Y',strtotime($event['start_date']));
$enddate = date('D M j Y',strtotime($event['end_date']));
$eventid = $event['id'];
list($title_place, $title_desc) = split(":",$event['title'],2);
if ($last != $startdate) {
$display = '<br />'.$startdate.'<br />';
}
$display .= l($title_place.' '.$title_desc, 'civicrm/event/info', array(), 'reset=1&id='.$event['id']).'<br />';
echo $display;
$count++;
$last = $startdate;
if ($count > 8) break;
// this limits the number of events to 8 - put in whatever number suits you
}
if ($count > 0) {
} else {
echo 'No events found.';
}
} else {
echo 'No events found.';
}
}
?>
Daniel Yoen answers:
Please let me know where you implement this scipt ?. :)
Socrates Ponnusamy comments:
As I said in my question above, I dont know where to put it. I just found this code and it seems it is pulling all the events.
Daniel Yoen comments:
I don't know if my solution is accordance with your wishes.
Create a file page-events.php in your theme folder.
fill with:
<?php
/*
Template Name: Events Page
*/
?>
<?php get_header(); ?>
<?php
function cmp_date($a, $b)
{
if ($a['start_date'] > $b['start_date'])
return 1;
if ($a['start_date'] < $b['start_date'])
return -1;
return 0;
}
if (module_exists('civicrm'))
{
civicrm_initialize(TRUE);
require_once 'api/v2/Event.php';
$params = array();
$myEvents = civicrm_event_search($params);
if ($myEvents)
{
$count = 0;
$last = '';
usort($myEvents, 'cmp_date');
foreach ($myEvents as $event)
{
$now = date('Y-m-d H:i:s');
if ($now > $event['start_date'])
continue;
$startdate = date('D M j Y', strtotime($event['start_date']));
$enddate = date('D M j Y', strtotime($event['end_date']));
$eventid = $event['id'];
list($title_place, $title_desc) = split(":", $event['title'], 2);
if ($last != $startdate)
{
$display = '<br />' . $startdate . '<br />';
}
$display .= l($title_place . ' ' . $title_desc, 'civicrm/event/info', array(), 'reset=1&id=' . $event['id']) . '<br />';
echo $display;
$count++;
$last = $startdate;
if ($count > 8)
break;
}
if ($count > 0)
{
}
else
{
echo 'No events found.';
}
}
else
{
echo 'No events found.';
}
}
?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Then, go to Pages, make new page. in Page Attributes select "Events Page" as template and Save
hope this help
Socrates Ponnusamy comments:
Daniel
Thanks for your response. I created a page like you said and added to my themes folder. I am using Karma theme. I then using that as a template I created a page and I am getting this error when I preview it...
Fatal error: Call to undefined function module_exists() in /var/www/wordpress/wp-content/themes/Karma/page-events.php on line 39
Looks like checking for civicrm is not working.
Thanks
Socrates
Lawrence Krubner answers:
There was some spam posted to the site earlier. I just made some changes to the site which should make spam less likely.