Are you up for a challenge- Need some help with a PHP calander

I have a calendar that I want to have a custom background color for every two days.(A-shift,B-shift,C-shift) Currently if I add color to the

it colors the full calendar. If I add more it breaks my calendar. Any help is appreciated.

[php]?>

	</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>
<< <?php echo ucfirst(date_i18n(get_option('dbem_small_calendar_month_format'), $calendar['month_start'])); ?> >>
<?php echo implode(' ',$calendar['row_headers']); ?>
[/php]

To create a calendar you will need to use either date() php function or DateTime() object (Class). I used a bit of both.

I know this is in OOP and you must likely won’t understand but this is how I started with making my calendar:
[php] /* Last month filler days (if needed) /
protected function lastMonth($date) {
$this->prev = new DateTime($date . “-1 Month”);
$this->prev->modify(“last day of this month”);
$this->prevMonth = $this->prev->format(‘w’); // Numeric day of the week the last month’s day falls on:
if ($this->prevMonth != 6) {
for ($x = $this->prevMonth; $x >= 0; $x–) {
$this->calendar[] = ‘

  • ’ . ($this->prev->format(‘t’) - $x) . ‘
  • ’ . “\n”;
    }
    } else {
    for ($x = 6; $x >= 0; $x–) {
    $this->calendar[] = ‘
  • ’ . ($this->prev->format(‘t’) - $x) . ‘
  • ’ . “\n”;
    }
    }
    }[/php]
    I used anchor tags and a div, but I have used a table in the past. Once I figure current month and the future month (if needed) I put it together for display like this ->
    [php] protected function form() {
    /
    Create a div box and an unordered list /
    $this->theForm .= ‘
    ’ . “\n” . ‘
      ’ . “\n”;
      / Create heading for the calendar /
      $this->theForm .= ‘
    • ’ . $this->current->format(‘F Y’) . ‘
    • ’ . “\n”;
      /
      Create days of the week heading /
      for ($x = 0; $x <= 6; $x++) {
      $this->theForm .= ‘
    • ’ . $this->alphaDay[$x] . ‘
    • ’ . “\n”;
      }
      /
      Create the actual days /
      foreach($this->calendar as $value) {
      $this->theForm .= $value;
      }
      /
      Close the HTML tags */
      return $this->theForm .= “
    \n
    \n”;
    }[/php]

    Like I say I don’t expect you to know the scripts I just shown, but to create a calendar be it the way I do it or by the table method. Create the days for the month stick it in an array and then create the whole calendar. I think you will find it easier to do it that way.

    What I did was create a mock-up calendar in HTML/CSS and then took the parts of the calendar and put it in php code.

    I believe

    [code]

    Jan 1 [/code]

    so you would do something like:
    for loop for week usually 1-4 or 1-5 weeks
    echo ‘

    ’;
    for loop for days 7 days
    echo ‘Days’;
    end of inner loop;
    echo ‘’;
    end of out loop

    that’s the logic of it.

    Sponsor our Newsletter | Privacy Policy | Terms of Service