[EventCalendar] recoding in-post events

Marc Boivin mjsdesign at gmail.com
Thu Mar 12 11:11:56 UTC 2009


Hi Morten,
I had that issue to. What I eneded up doing is creating a  
ec3_the_events() function.

Here's how I did it:

Change the line
 >return ec3_get_schedule() . $post_content;
from eventcalendar3.php so it reads:
 >return $post_content;

Add this function to the template-functions.php file:

// Created by Marc Boivin <mjsdesign at gmail.com>
/*
  * Try to match the the_content() function of wordpress.
  * You can get the default rendering
  * or retrive an array of event for you to handle.
  * If you need the layout of the array, just call a print_r,
  * it's pretty simple.
*/
function ec3_the_events($echo=1, $formats = 'd M Y')
{
	if($echo)
	{
		echo ec3_get_schedule();
		return true;
	}
	
	global $ec3,$post;
	// We must be in a wordpress loop in order for this to work
	if(!$post || !$post->ec3_schedule)
		return '';
	
	// Gather the demanded date information
	$asked_formats = split(' ', $formats);
	$events = array();
	$i = 0;
	
	foreach($post->ec3_schedule as $s)
	{
		// Format time
	  	foreach($asked_formats as $format)
	  	{
	     	$events[$i]['start'][$format] = mysql2date($format,$s->start);
			$events[$i]['end'][$format] = mysql2date($format,$s->end);	
	  	}

	    if($s->allday)
	    {
	      $events[$i]['allday'] = __('all day', 'ec3');
	    }
		$i++;
	}
	
	return $events;
	
}

Now all you have to do to create a custom look for your event is to  
call ec3_the_events()

Here's an example. I wanted to display only the starting day of the  
week, day number and month of an event:

<?php $events = ec3_the_events(0, 'l d F H i');
			
				foreach($events as $event)
				{
					?>
					<div class="fp_event">
						<ul>
							<li class="event_jour"><?php echo $event['start']['l'] ?></li>
							<li class="event_date"><?php echo $event['start']['d'] ?></li>
							<li class="event_mois"><?php echo $event['start']['F'] ?></li>
							
						</ul>
						<h1 class="title">
							<?php the_title() ?>
						</h1>
						<h2 class="event_infos"><?php $place =  
get_post_custom_values('endroit'); echo $place[0]; ?> • DÉBUTE À <?php  
echo $event['start']['H'].'h'.$event['start']['i'];  ?> • ADMISSION <? 
php $prix = get_post_custom_values('Prix'); echo $prix[0];?></h2>
						<div class="clearer"></div>
					</div>
					<?php
				}
			?>

What is important here is that the obscure characters in the function  
call 'l d F H i' each represent a date information from PHP's date  
function (http://ca.php.net/manual/en/function.date.php) the first  
parameter (0) tells the function to return an array instead of  
printing out the default layout for the events.

For each event from a post, you get 2 arrays: start and end which  
holds all the information you asked. There you have it, custom infos  
for custom layouts. Teh code is not completely tested though.

Marc

On 11-Mar-09, at 11:29 PM, Adam Houston wrote:

> Morten -
>
> I did the same thing. Here's the code I use...I haven't had it this  
> way for very long so who knows if issues may arise later. But for  
> me, it has worked great. You can see it in place at http://www.haynerlibrary.org
>
> Replace the appropriate section of "template-functions-new" with the  
> following:
>
>
>
> /** Formats the schedule for the current post as one or more  
> 'iconlets'.
> *  Returns the HTML fragment as a string. */
> function ec3_get_iconlets()
> {
>  if(!ec3_is_event())
>    return '';
>
>  global $ec3;
>  $result='';
>  $current=false;
>  $this_year=date('Y');
>  for($evt=ec3_iter_post_events(); $evt->valid(); $evt->next())
>  {
>    $year_start =ec3_get_start_date('Y');
>    $month_start=ec3_get_start_date('M');
>    $day_start  =ec3_get_start_date('j');
>    // Don't bother about intra-day details.
>    if($current==$day_start.$month_start.$year_start)
>      continue;
>    $current=$day_start.$month_start.$year_start;
>    // Grey-out past events.
>    if($ec3->event->active)
>      $active ='';
>    else
>      $active =' ec3_past';
>    // Only put the year in if it isn't *this* year.
>    if($year_start!=$this_year)
>      $month_start.='&nbsp;&rsquo;'.substr($year_start,2);
>    // OK, make the iconlet.
>    $result.="<div";
>    if(!$ec3->event->allday)
>    {
>      // Event with start time.
>      $time_start=ec3_get_start_time();
>      $result.=" class='ec3_iconlet$active'><span class='ec3_month'> 
> $month_start</span>"
>             . "<span class='ec3_day'>$day_start</span>"
>             . "<span class='ec3_time'>$time_start</span>";
>    }
>    elseif(substr($ec3->event->start,0,10) == substr($ec3->event->end, 
> 0,10))
>    {
>      // Single, all-day event.
>      $result.=" class='ec3_iconlet$active'><span class='ec3_month'> 
> $month_start</span>"
>             . "<span class='ec3_day'>$day_start</span>"
>             . "<span class='ec3_time'>All day</span>";
>    }
>    else
>    {
>      // Multi-day event.
>      $month_end=ec3_get_end_date('M');
>      $day_end  =ec3_get_end_date('j');
> 	
> 		if($month_start==$month_end)
> 		{
> 		  $result.=" class='ec3_multi_iconlet$active'><span  
> class='ec3_multi_month'>"
> 				 .  "<span class='ec3_multi_month_end'>$month_start</span></ 
> span>";
> 		}
> 		else
> 		{
> 		  $result.=" class='ec3_multi_iconlet$active'><span  
> class='ec3_multi_month'>"
> 				 .  "<span class='ec3_multi_month_start'>$month_start</ 
> span>&ndash;"
> 				 .  "<span class='ec3_multi_month_end'>$month_end</span></span>";
> 		}
>      $result.="<span class='ec3_multi_day'>"
>             .  "<span class='ec3_multi_day_start'>$day_start</ 
> span>&ndash;"
>             .  "<span class='ec3_multi_day_end'>$day_end</span></ 
> span>"
>             . "<span class='ec3_multi_time'>All day</span>";
>    }
>    $result.="</div>\n";
>  }
>  return apply_filters( 'ec3_filter_iconlets', $result );
> }
>
>
>
>
> Thanks,
>
> Adam Houston
>
>
>
>
> On Mar 11, 2009, at 9:31 PM, Morten Rand-Hendriksen wrote:
>
>> I want to restyle the box that shows up inside posts to fit with my  
>> overall layout. The big problem is that it’s using tables which  
>> makes it very hard to deal with. Can someone direct me towards  
>> where in the plugin the actual in-post code is generated so I can  
>> convert it to CSS instead of a clunky table? It’ll make it a lot  
>> easier to style and position the box.
>>
>> Thanks
>>
>> morten
>>
>> _______________________________________________
>> Blog: http://wpcal.firetree.net/
>> EventCalendar at firetree.net mailing list
>> Unsubscribe: http://penguin.firetree.net/eventcalendar
>
>
>
>
>
>
> _______________________________________________
> Blog: http://wpcal.firetree.net/
> EventCalendar at firetree.net mailing list
> Unsubscribe: http://penguin.firetree.net/eventcalendar




More information about the EventCalendar mailing list