我想在此日历上每两天创建一个不同的颜色背景。表示:
目前,如果我将style="background-color:red"
添加到<td>
标记,则会为整个日历添加颜色。
<?php
?>
<table class="em-calendar">
<thead>
<tr>
<td><a class="em-calnav em-calnav-prev" href="<?php echo $calendar['links']['previous_url']; ?>" rel="nofollow"><<</a></td>
<td class="month_name" colspan="5"><?php echo ucfirst(date_i18n(get_option('dbem_small_calendar_month_format'), $calendar['month_start'])); ?></td>
<td><a class="em-calnav em-calnav-next" href="<?php echo $calendar['links']['next_url']; ?>" rel="nofollow">>></a></td>
</tr>
</thead>
<tbody>
<tr class="days-names" style="background-color:#AD1010">
<td><?php echo implode('</td><td>',$calendar['row_headers']); ?></td>
</tr>
<tr>
<?php
$cal_count = count($calendar['cells']);
$col_count = $count = 1; //this counts collumns in the $calendar_array['cells'] array
$col_max = count($calendar['row_headers']); //each time this collumn number is reached, we create a new collumn, the number of cells should divide evenly by the number of row_headers
foreach($calendar['cells'] as $date => $cell_data ){
$class = ( !empty($cell_data['events']) && count($cell_data['events']) > 0 ) ? 'eventful':'eventless';
if(!empty($cell_data['type'])){
$class .= "-".$cell_data['type'];
}
?>
<td class="<?php echo $class; ?>">
<?php if( !empty($cell_data['events']) && count($cell_data['events']) > 0 ): ?>
<a href="<?php echo esc_url($cell_data['link']); ?>" title="<?php echo esc_attr($cell_data['link_title']); ?>"><?php echo date('j',$cell_data['date']); ?></a>
<?php else:?>
<?php echo date('j',$cell_data['date']); ?>
<?php endif; ?>
</td>
<?php
//create a new row once we reach the end of a table collumn
$col_count= ($col_count == $col_max ) ? 1 : $col_count+1;
echo ($col_count == 1 && $count < $cal_count) ? '</tr><tr>':'';
$count ++;
}
?>
</tr>
</tbody>
</table>