開催中を示すプレースホルダーを作成する

function my_em_custom_placeholders($replace, $EM_Event, $result){
switch( $result ){
case ‘#_NOW’:
$dt = new DateTime();
$dt->setTimeZone(new DateTimeZone(‘Asia/Tokyo’));
$today = $dt->format(‘Y-m-d’);

// 比較する日付を設定
$target_day_s = $EM_Event->event_start_date;
$target_day_e = $EM_Event->event_end_date;

// 日付を比較
if( (strtotime($target_day_s) <= strtotime($today)) && (strtotime($target_day_e)) >= strtotime($today)) {
$replace = ‘開催中!’;
} else {
$replace = ”;
}
break;
}
return $replace;
}
add_filter(’em_event_output_placeholder’,’my_em_custom_placeholders’,1,3);?>

ここから抜粋
http://wpgatera.matrix.jp/post-1480/

1
2
3
4
5
6
7
8
<?php
$str_shortcode = "[events_list scope='future']";
$str_shortcode .= "<p class='dates'>【開催日】#_EVENTDATES #_EVENTTIMES</p>";
$str_shortcode .= "<p class='title'>#_EVENTLINK #_NOW</p>";
$str_shortcode .= "[/events_list]";
 
echo do_shortcode($str_shortcode);
?>

イベント一覧をショートコードを使って表示する。

一覧を表示させたいところに下記を追加

1
2
3
4
5
6
7
8
<?php
$str_shortcode = "[events_list scope='future']";
$str_shortcode .= "<p class='dates'>【開催日】#_EVENTDATES #_EVENTTIMES</p>";
$str_shortcode .= "<p class='title'>#_EVENTLINK #_NOW</p>";
$str_shortcode .= "[/events_list]";
 
echo do_shortcode($str_shortcode);
?>

開催中の表示

case ‘#_RESERVE’:
//This doesn’t consider reserved (i.e. pending) bookings as ‘booked’
$booked = 0;
$max = 0;
foreach( $this->get_tickets()->tickets as $EM_Ticket ){
if( $EM_Ticket->is_displayable() ) {

$booked = $EM_Ticket->get_booked_spaces();
$max = $EM_Ticket->ticket_spaces;

}
}
global $EM_Event;
$replace = “受付終了”;
if ($max > $booked) {
if ($max – $booked > 3) {
$replace = “受付中”;
} else {
$replace = “残りわずか”;
}
}
break;