ai1ec_box.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. function set_ai1ec_join($join, &$wp_query) {
  3. global $wpdb;
  4. $db_prefix=$wpdb->prefix;
  5. $join .=" JOIN ".$db_prefix."ai1ec_events
  6. ON $wpdb->posts.ID = ".$db_prefix."ai1ec_events.post_id";
  7. return $join;
  8. }
  9. function set_ai1ec_where( $where, &$wp_query ){
  10. global $wpdb;
  11. $db_prefix=$wpdb->prefix;
  12. if(! is_admin() && $wp_query->post_type ='ai3ec_event'){
  13. date_default_timezone_set("Europe/Rome");
  14. $where .= ' AND '. $db_prefix.'ai1ec_events.end >= \''.time().'\'';
  15. return $where;
  16. }
  17. }
  18. function set_ai1ec_limits( $limit, $query ) {
  19. return 'LIMIT 0, 5';
  20. }
  21. add_filter('posts_orderby', 'set_ai1ec_orderby');
  22. function set_ai1ec_orderby($orderby) {
  23. global $wpdb;
  24. $db_prefix=$wpdb->prefix;
  25. $orderby = $db_prefix."ai1ec_events.start ASC";
  26. return $orderby;
  27. }
  28. function get_ai1ec_box($attrs){ ?>
  29. <?php
  30. global $count2 ;
  31. $box_title = "Prossimi Eventi";
  32. if( !empty($attrs['title']) )
  33. $box_title = $attrs['title'];
  34. $Posts = 12;
  35. if( !empty($attrs['num']) )
  36. $Posts = $attrs['num'];
  37. $home_layout = '';
  38. if( !empty($attrs['layout']) )
  39. $home_layout = $attrs['layout'];
  40. $offset = '';
  41. if( !empty($attrs['offset']) )
  42. $home_layout = $attrs['offset'];
  43. $page_ids=Array();
  44. if( !empty($attrs['ids']) )
  45. $page_ids=explode(",",$attrs['ids']);
  46. $args=Array(
  47. 'post_type'=> 'ai1ec_event',
  48. 'no_found_rows' => 1,
  49. 'posts_per_page' => $Posts,
  50. 'offset'=> '',
  51. 'tax_query' => array(
  52. array(
  53. 'field' => 'id',
  54. 'terms' => $page_ids,
  55. 'taxonomy' => 'events_categories',
  56. )
  57. ),
  58. );
  59. add_filter('posts_join', 'set_ai1ec_join',10,2);
  60. add_filter( 'posts_where', 'set_ai1ec_where', 10, 2 );
  61. add_filter('posts_orderby', 'set_ai1ec_orderby');
  62. add_filter( 'post_limits', 'set_ai1ec_limits', 10, 2 );
  63. //http://codex.wordpress.org/Class_Reference/WP_Query
  64. $cat_query = new WP_Query($args);
  65. remove_filter('posts_join', 'set_ai1ec_join');
  66. remove_filter( 'posts_where', 'set_ai1ec_where');
  67. remove_filter('posts_orderby', 'set_ai1ec_orderby');
  68. remove_filter( 'post_limits', 'set_ai1ec_limits');
  69. $count = 0;
  70. ?>
  71. <?php if( $home_layout == '2c'): //************** 2C ****************************************************** ?>
  72. <?php $count2++; ?>
  73. <section class="cat-box column2 <?php if($count2 == 2) { echo 'last-column'; $count2=0; } ?>">
  74. <div class="cat-box-title">
  75. <h2><?php echo $box_title ; ?></h2>
  76. <div class="stripe-line"></div>
  77. </div><!-- post-thumbnail /-->
  78. <div class="cat-box-content">
  79. <?php if($cat_query->have_posts()): ?>
  80. <ul>
  81. <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
  82. <?php if($count == 1) : ?>
  83. <li <?php tie_post_class('first-news'); ?>>
  84. <div class="inner-content">
  85. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  86. <div class="post-thumbnail">
  87. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  88. <?php tie_thumb( 'tie-medium' ); ?>
  89. <span class="overlay-icon"></span>
  90. </a>
  91. </div><!-- post-thumbnail /-->
  92. <?php endif; ?>
  93. <h2 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  94. <div class="entry">
  95. <?php tie_excerpt_home() ?>
  96. <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
  97. </div>
  98. </div>
  99. </li><!-- .first-news -->
  100. <?php else: ?>
  101. <li <?php tie_post_class(); ?>>
  102. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  103. <div class="post-thumbnail">
  104. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php tie_thumb(); ?><span class="overlay-icon"></span></a>
  105. </div><!-- post-thumbnail /-->
  106. <?php endif; ?>
  107. <h3 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
  108. <div class="entry">
  109. <?php tie_excerpt_home() ?>
  110. </div>
  111. </li>
  112. <?php endif; ?>
  113. <?php endwhile;?>
  114. </ul>
  115. <?php endif; ?>
  116. </div><!-- .cat-box-content /-->
  117. </section> <!-- Two Columns -->
  118. <?php elseif( $home_layout == '1c' ): //************** 1C ****************************************************** ?>
  119. <section class="cat-box wide-box">
  120. <div class="cat-box-title">
  121. <h2><?php echo $box_title ; ?></h2>
  122. <div class="stripe-line"></div>
  123. </div><!-- post-thumbnail /-->
  124. <div class="cat-box-content">
  125. <?php if($cat_query->have_posts()): ?>
  126. <ul>
  127. <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
  128. <?php if($count == 1) : ?>
  129. <li <?php tie_post_class( 'first-news' ); ?>>
  130. <div class="inner-content">
  131. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  132. <div class="post-thumbnail">
  133. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  134. <?php tie_thumb( 'tie-large' ); ?>
  135. <span class="overlay-icon"></span>
  136. </a>
  137. </div><!-- post-thumbnail /-->
  138. <?php endif; ?>
  139. <h2 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  140. <div class="entry">
  141. <?php tie_excerpt_home() ?>
  142. <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
  143. </div>
  144. </div>
  145. </li><!-- .first-news -->
  146. <?php else: ?>
  147. <li <?php tie_post_class(); ?>>
  148. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  149. <div class="post-thumbnail">
  150. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php tie_thumb(); ?><span class="overlay-icon"></span></a>
  151. </div><!-- post-thumbnail /-->
  152. <?php endif; ?>
  153. <h3 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
  154. <div class="entry">
  155. <?php tie_excerpt_home() ?>
  156. </div>
  157. </li>
  158. <?php endif; ?>
  159. <?php endwhile;?>
  160. </ul>
  161. <div class="clear"></div>
  162. <?php endif; ?>
  163. </div><!-- .cat-box-content /-->
  164. </section><!-- Wide Box -->
  165. <?php else : //************** list ********************************************************************************** ?>
  166. <section class="cat-box list-box">
  167. <div class="cat-box-title">
  168. <h2><?php echo $box_title ; ?></h2>
  169. <div class="stripe-line"></div>
  170. </div><!-- post-thumbnail /-->
  171. <div class="cat-box-content">
  172. <?php if($cat_query->have_posts()): ?>
  173. <ul>
  174. <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
  175. <?php if($count == 1) : ?>
  176. <li <?php tie_post_class( 'first-news' ); ?>>
  177. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  178. <div class="post-thumbnail">
  179. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  180. <?php tie_thumb( 'tie-medium' ); ?>
  181. <span class="overlay-icon"></span>
  182. </a>
  183. </div><!-- post-thumbnail /-->
  184. <?php endif; ?>
  185. <h2 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
  186. <div class="entry">
  187. <?php tie_excerpt_home() ?>
  188. <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
  189. </div>
  190. </li><!-- .first-news -->
  191. <?php else: ?>
  192. <li <?php tie_post_class( 'other-news' ); ?>>
  193. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  194. <div class="post-thumbnail">
  195. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php tie_thumb(); ?><span class="overlay-icon"></span></a>
  196. </div><!-- post-thumbnail /-->
  197. <?php endif; ?>
  198. <h3 class="post-box-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
  199. <div class="entry">
  200. <?php tie_excerpt_home() ?>
  201. </div>
  202. </li>
  203. <?php endif; ?>
  204. <?php endwhile;?>
  205. </ul>
  206. <div class="clear"></div>
  207. <?php endif; ?>
  208. </div><!-- .cat-box-content /-->
  209. </section><!-- List Box -->
  210. <?php endif; ?>
  211. <?php } ?>