CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Add "register" button to this loop
Pages: [1]

Author Topic: Add "register" button to this loop  (Read 1634 times)

jddarling

  • Guest
Add "register" button to this loop
March 15, 2008, 03:41:46 pm
How would I add a "register" button into this loop?

Code: [Select]
<?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';
  
// This example limits listing to public and active events
  
$params = array ('is_public'     => 1, 'is_active'     => 1);
  
$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 = '<strong>'.$startdate.'</strong><br />';
      } else {
        
$display = '';
      }
      
$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.';
  }
}
?>


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Add "register" button to this loop
March 15, 2008, 06:25:05 pm

I assume u mean a register link. If so you can copy the info link line and do exactly the same thing but change the url from civicrm/event/info to civicrm/event/register. However having both the info and register link might be a bit confusing to the end user

If a button, you'll need to check drupal coding guidelines to see how they add a form and a button etc

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

jddarling

  • Guest
Re: Add "register" button to this loop
March 16, 2008, 01:46:45 pm
Right, I was able to get that far, but I'd prefer just to put a text link beneath each event link that says "register now"

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Add "register" button to this loop

This forum was archived on 2017-11-26.