我需要按照年份和季节对日期进行分组 目标是实现这样的下拉菜单:
这是我的测试代码这么久, 此代码生成一个列表,其中包含每个帖子一年/一段时间, 如何修改此项仅显示此期间是否有帖子。 (如果有,则显示下拉列表中的年份/季节)
foreach ($event as $post) {
setup_postdata($post);
$printdate = DateTime::createFromFormat('Ymd', get_post_meta($post->ID, 'datum', 'true'));
$year = $printdate->format('Y');
// I want to use the year to group the posts
// this is the first period
$start_date = $year.'-01-1';
$end_date = $year.'-06-31';
$date_from_user = $printdate->format('Y-m-d');
if (( $date_from_user >= $start_date ) && ( $date_from_user <= $end_date ) )
{ ?>
<h3><?php echo $year; ?></h3>
<h4> Summer </h4>
<? }
// this is the second period (or i use simply "else" here)
$start_date2 = $year.'-07-1';
$end_date2 = $year.'-12-31';
if (( $date_from_user >= $start_date2 ) && ( $date_from_user <= $end_date2 ) )
{ ?>
<h3><?php echo $year; ?></h3>
<h4> Winter </h4>
<? }
}
?>
提前感谢!!