Events Made Easy › Forums › Bug fixed or feature request implemented › Countdown to next event
Tagged: countdown, counter, daycounter
- This topic has 3 replies, 3 voices, and was last updated 13 years, 4 months ago by Franky.
-
AuthorPosts
-
Tue 17 May 2011 at 17:10 #42822AnonymousInactive
I would like to add a countdown for the next event
e.g. “14 days, 16 hour, 35 minutes up to the next gig”
Any ideas, how to solve this?
Tue 17 May 2011 at 21:19 #47741FrankyKeymasterFor the moment this requires own coding: call the api function:
eme_get_events(1);
and play with the result.
Fri 29 Jul 2011 at 09:43 #47742AnonymousInactiveI’ve played a little bit but have the problem that i cant get the Date from the next event. Maybe it helps someone to finish a counter function. In my functions.php i’ve add this:
/**
* Filter to enable Shortcodes from Sidebars (Use only if you need it)
*/
add_filter('widget_text', 'do_shortcode');
if( function_exists( 'date_default_timezone_set' ) )
{
// Set the default timezone http://www.php.net/manual/de/timezones.php
date_default_timezone_set( 'Europe/Berlin' );
}
if ( ! function_exists( 'counter' ) ) :
/**
* Shortcode for the eme-plugin that count days to event
*
* Usage [counter]
*/
function counter()
{
function count_days( $a, $b )
{
// function found at http://snipplr.com/view/2223/get-number-of-days-between-two-dates/
// First we need to break these dates into their constituent parts:
$gd_a = getdate( $a );
$gd_b = getdate( $b );
// Now recreate these timestamps, based upon noon on each day
// The specific time doesn't matter but it must be the same each day
$a_new = mktime( 12, 0, 0, $gd_a, $gd_a, $gd_a );
$b_new = mktime( 12, 0, 0, $gd_b, $gd_b, $gd_b );
// Subtract these two numbers and divide by the number of seconds in a
// day. Round the result since crossing over a daylight savings time
// barrier will cause this time to be off by an hour or two.
return round( abs( $a_new - $b_new ) / 86400 );
}
// Date from Now
$inicial = date("Y-m-d");
// Date from Event wont work now :-(
$fin = eme_get_event("limit=1&scope=future&format=#Y-#m-#d");
// this will work fine
//$fin = date("2011-08-03");
// Timestamps for the Dates
$now = strtotime("$inicial");
$event = strtotime(stripslashes("$fin"));
// Count Days between Dates
$days = count_days( $now, $event );
// Return pure Number of Days
return $days;
}
add_shortcode('counter', 'counter');
endif;
I have Use in the Widget “Events List” the Shortcode [counter] where i want to place the Number of Days.
Fri 29 Jul 2011 at 12:58 #47743FrankyKeymasterI created the function eme_daydifference in trunk. Your counter function would become (you used eme_get_event, it should be eme_get_events(1) like I mentioned before. I added this to trunk, so it will be in the next version:
# return number of days to next event, or to the specified event ID
function eme_countdown() {
extract ( shortcode_atts ( array ('id'=>''), $atts ) );
$now = date("Y-m-d");
if ($id!="") {
$event=eme_get_event($id);
} else {
$newest_event_array=eme_get_events(1);
$event=$newest_event_array[0];
}
$end_date=$event['event_start_date'];
return eme_daydifference($now,$end_date);
}
add_shortcode('events_countdown', 'eme_countdown');Btw: the “add_filter(‘widget_text’, ‘do_shortcode’);” is not needed: it’s an option in EME that you can activate.
-
AuthorPosts
- The forum ‘Bug fixed or feature request implemented’ is closed to new topics and replies.