我目前正在尝试让我的事件列表代码按月打印标题。所以基本上是这样的:
十月
9月事件
事件等。。。
现在,它只会在一月回响。我认为这可能与$currentmount或strotime()有关,但我不确定是什么原因。有什么建议吗?我一直在看this post 试着把它弄明白。
谢谢
<?php
$args = array(
\'post_type\' => \'events\',
\'orderby\' => \'meta_value\',
\'meta_key\' => \'tf_events_startdate\',
\'order\' => \'DESC\'
);
$my_query = new WP_Query($args);
if ($my_query->have_posts()) : while ($my_query->have_posts()) :
$my_query->the_post();
$custom = get_post_custom(get_the_ID());
// dates
$sd = $custom["tf_events_startdate"][0];
$ed = $custom["tf_events_enddate"][0];
// - local time format -
$time_format = get_option(\'time_format\');
$stime = date($time_format, $sd);
$etime = date($time_format, $ed);
// set headers
if(!isset($currentMonth) || $currentMonth != date("m", strtotime($sd))){
$currentMonth = date("m", strtotime($sd));
echo \'<h2>\'.date("F", strtotime($sd)).\'</h2>\';
}?>
<ul>
<li>
<strong><a href="<?php the_permalink();?>"><?php the_title();?></a></strong>
<br />
<?php // - determine if it\'s a new day -
$longdate = date("l, M j, Y", $sd);
if ($daycheck == null) { echo $longdate; }
if ($daycheck != $longdate && $daycheck != null) { echo $longdate; } ?>
<br />
<?php echo $stime;?>
<hr />
</li>
</ul>
<?php endwhile; else: ?>
<ul id="events">
<li><?php _e(\'No Events Yet .\'); ?></li>
</ul>
<?php endif; ?>