这是代码
edate = get_field('expire_date');
$currentDateTime = date('Y-m-d');
$currentMonth = date('M');
$earlier = new DateTime($edate);
$later = new DateTime($currentDateTime);
$daysrem = $later->diff($earlier)->format("%a");
$status = get_field('status');
?>
<tr>
<td class=""><?php the_field('expire_date')?></td>
<td><?php echo $daysrem; ?></td>
<td class="<?php the_field('status') ?>"><?php the_field('status') ?></td>
</tr>
如果到期日期是当月,则状态应更改为橙色的背景色。 怎么做,请帮忙!
答案 0 :(得分:1)
首先,比较月份,如果相同,将'orangeClassName'添加到php变量中:
$tdStyle = ($currentMonth == date('M',strtotime(the_field('expire_date')))) ? 'orangeClassName' : '';
然后在您的变量中包含该变量:
<td class="<?php echo $tdStyle;?>"><?php the_field('expire_date')?></td>
并将相关的类添加到您的CSS:
.orangeClassName {background:orange;}
请注意,这只是检查月份是否相同,因此04-2020 == 04-2019也会返回true