这是一个可以放入函数中的函数。php。
function get_current_event() {
global $post;
$now = get_the_time(\'U\');
$year = get_the_time(\'Y\');
if($now >= strtotime("January 1 $year") && $now < strtotime("March 1 $year")) {
return get_post_meta($post->ID,\'eventA\',true);
}
if($now >= strtotime("March 1 $year") && $now < strtotime("October 15 $year")) {
return get_post_meta($post->ID,\'eventB\',true);
}
$nextyear = $year+1;
if($now >= strtotime("October 15 $year") && $now < strtotime("January 1 $nextyear")) {
return get_post_meta($post->ID,\'eventC\',true);
}
return false;
}
然后,您可以将其放入模板中:
print get_current_event();