Don't like ads? PRO users don't see any ads ;-)
Guest

Ivyowl01

By: a guest on Mar 10th, 2011  |  syntax: None  |  size: 2.96 KB  |  hits: 135  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function events_featured ( $atts ) {
  2.  
  3. // - define arguments -
  4. extract(shortcode_atts(array(
  5.     'limit' => '100', // # of events to show
  6.     'group' => ' ',
  7.  ), $atts));
  8.  
  9. // ===== OUTPUT FUNCTION =====
  10.  
  11. ob_start();
  12.  
  13. // ===== LOOP: FULL EVENTS SECTION =====
  14.  
  15. // - hide events that are older than 6am today (because some parties go past your bedtime) -
  16.  
  17. $today6am = strtotime('today 6:00') + ( get_option( 'gmt_offset' ) * 3600 );
  18.  
  19. // - query -
  20. global $wpdb;
  21.  
  22. $querystr = "
  23. SELECT *
  24. FROM $wpdb->postmeta metastart, $wpdb->postmeta metaend, $wpdb->posts
  25. LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
  26. LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  27. LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  28. LEFT JOIN $wpdb->terms ON($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id)
  29. WHERE ($wpdb->posts.ID = metastart.post_id AND $wpdb->posts.ID = metaend.post_id)
  30. AND $wpdb->term_taxonomy.taxonomy = 'tf_eventcategory'
  31. AND $wpdb->terms.name = '$group'
  32. AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $today6am )
  33. AND metastart.meta_key = 'tf_events_enddate'
  34. AND $wpdb->posts.post_type = 'tf_events'
  35. AND $wpdb->posts.post_status = 'publish'
  36. ORDER BY metastart.meta_value ASC LIMIT $limit
  37. ";
  38.  
  39. $events = $wpdb->get_results($querystr, OBJECT);
  40.  
  41.  
  42. // - declare fresh day -
  43. $daycheck = null;
  44.  
  45. // - loop -
  46. if ($events):
  47. global $post;
  48. foreach ($events as $post):
  49. setup_postdata($post);
  50.  
  51. // - custom variables -
  52. $custom = get_post_custom(get_the_ID());
  53. $sd = $custom["tf_events_startdate"][0];
  54. $ed = $custom["tf_events_enddate"][0];
  55.  
  56. // - determine if it's a new day -
  57. $longdate = date("l, F j, Y", $sd);
  58. if ($daycheck == null) { echo '<h2 class="events-featured">' . $longdate . '</h2>'; }
  59. if ($daycheck != $longdate && $daycheck != null) { echo '<h2 class="events-featured">' . $longdate . '</h2>'; }
  60.  
  61. // - local time format -
  62. $time_format = get_option('time_format');
  63. $stime = date($time_format, $sd);
  64. $etime = date($time_format, $ed);
  65.  
  66. $postlinkid = get_the_ID();
  67.  
  68. // - output - ?>
  69. <div class="events-featured">
  70.     <div class="text">
  71.         <div class="title">
  72.             <div class="time"><?php echo $stime . ' - ' . $etime; ?></div>
  73.             <div class="eventtext"><a href="<?php echo get_permalink($postlinkid); ?>"><?php the_title(); ?></a></div>
  74.         </div>
  75.     </div>
  76.      <div class="desc"><?php if (strlen($post->post_content) > 150) { echo substr($post->post_content, 0, 150) . '...'; } else { echo $post->post_content; } ?></div>
  77. </div>
  78. <?php
  79.  
  80. // - fill daycheck with the current day -
  81. $daycheck = $longdate;
  82.  
  83. endforeach;
  84. else :
  85. endif;
  86.  
  87. // ===== RETURN: FULL EVENTS SECTION =====
  88.  
  89. $output = ob_get_contents();
  90. ob_end_clean();
  91. return $output;
  92. }
  93.  
  94. add_shortcode('events-featured', 'events_featured'); // You can now call onto this shortcode with [events-featured limit='20']