eventsmanager

calendar small table.td background color per event category

Oct 9th, 2013
349
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. * This custom calendar-small.php template will change the table td background according to Event Category color
  5. *
  6. * To use template:
  7. * - create these folders inside your theme directory - wp-content > themes > Your Theme > plugins > events-manager > template > calendar-small.php
  8. */
  9.  
  10.  
  11. /*
  12. * This file contains the HTML generated for small calendars. You can copy this file to yourthemefolder/plugins/events/templates and modify it in an upgrade-safe manner.
  13. *
  14. * There are two variables made available to you:
  15. *
  16. * $calendar - contains an array of information regarding the calendar and is used to generate the content
  17. * $args - the arguments passed to EM_Calendar::output()
  18. *
  19. * Note that leaving the class names for the previous/next links will keep the AJAX navigation working.
  20. */
  21. ?>
  22. <table class="em-calendar">
  23. <thead>
  24. <tr>
  25. <td><a class="em-calnav em-calnav-prev" href="<?php echo $calendar['links']['previous_url']; ?>" rel="nofollow">&lt;&lt;</a></td>
  26. <td class="month_name" colspan="5"><?php echo ucfirst(date_i18n(get_option('dbem_small_calendar_month_format'), $calendar['month_start'])); ?></td>
  27. <td><a class="em-calnav em-calnav-next" href="<?php echo $calendar['links']['next_url']; ?>" rel="nofollow">&gt;&gt;</a></td>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <tr class="days-names">
  32. <td><?php echo implode('</td><td>',$calendar['row_headers']); ?></td>
  33. </tr>
  34. <tr>
  35. <?php
  36. $cal_count = count($calendar['cells']);
  37. $col_count = $count = 1; //this counts collumns in the $calendar_array['cells'] array
  38. $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
  39. foreach($calendar['cells'] as $date => $cell_data ){
  40. $class = ( !empty($cell_data['events']) && count($cell_data['events']) > 0 ) ? 'eventful':'eventless';
  41. if(!empty($cell_data['type'])){
  42. $class .= "-".$cell_data['type'];
  43. }
  44. ?>
  45.  
  46. <?php
  47. /*
  48. * Get the events of the day and get the category color
  49. */
  50. ?>
  51. <?php if ( !empty($cell_data['events']) ) foreach( $cell_data['events'] as $EM_Event ): break; endforeach; ?>
  52. <?php $category_color = (!empty($cell_data['events'])) ? $EM_Event->output("#_CATEGORYCOLOR") : '' ; ?>
  53.  
  54. <td class="<?php echo $class; ?>" <?php if ( !empty($category_color) ){ ?> style="background-color:<?php echo $category_color; ?>" <?php } ?> >
  55. <?php if( !empty($cell_data['events']) && count($cell_data['events']) > 0 ): ?>
  56. <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>
  57. <?php else:?>
  58. <?php echo date('j',$cell_data['date']); ?>
  59. <?php endif; ?>
  60. </td>
  61. <?php
  62. //create a new row once we reach the end of a table collumn
  63. $col_count= ($col_count == $col_max ) ? 1 : $col_count+1;
  64. echo ($col_count == 1 && $count < $cal_count) ? '</tr><tr>':'';
  65. $count ++;
  66. }
  67. ?>
  68. </tr>
  69. </tbody>
  70. </table>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×