Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$10
Listing active civiCRM events in Wordpress
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 /><b>'.$startdate.'</b><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.';
}
}
?>
Socrates Ponnusamy | 07/01/12 at 2:54am
Edit
Tutorial: How to assign prize money
(3) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
07/01/12
3:10amDaniel Yoen says:Please let me know where you implement this scipt ?. :)
- 07/01/12 3:40am
Socrates Ponnusamy says: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.
- 07/01/12 4:14am
Daniel Yoen says: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 /><b>' . $startdate . '</b><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 - 07/01/12 9:26pm
Socrates Ponnusamy says: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
- 07/01/12 3:40am
-

Last edited:
07/01/12
4:10am -
Last edited:
07/03/12
10:30pmLawrence Krubner says:There was some spam posted to the site earlier. I just made some changes to the site which should make spam less likely.
This question has expired.
Current status of this question: Community pot
Please log in to add additional discourse to this page.
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
