ai1ec_box.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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['box_title']) )
  33. $box_title = $attrs['box_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. $args=Array(
  41. 'post_type'=> 'ai1ec_event',
  42. 'no_found_rows' => 1,
  43. 'posts_per_page' =>$Posts,
  44. 'offset'=> '',
  45. 'tax_query' => array(
  46. array(
  47. 'field' => 'id',
  48. 'terms' => array(34),
  49. 'taxonomy' => 'events_categories',
  50. )
  51. ),
  52. );
  53. add_filter('posts_join', 'set_ai1ec_join',10,2);
  54. add_filter( 'posts_where', 'set_ai1ec_where', 10, 2 );
  55. add_filter('posts_orderby', 'set_ai1ec_orderby');
  56. add_filter( 'post_limits', 'set_ai1ec_limits', 10, 2 );
  57. //http://codex.wordpress.org/Class_Reference/WP_Query
  58. $cat_query = new WP_Query($args);
  59. remove_filter('posts_join', 'set_ai1ec_join');
  60. remove_filter( 'posts_where', 'set_ai1ec_where');
  61. remove_filter('posts_orderby', 'set_ai1ec_orderby');
  62. remove_filter( 'post_limits', 'set_ai1ec_limits');
  63. $count = 0;
  64. ?>
  65. <?php if( $home_layout == '2c'): //************** 2C ****************************************************** ?>
  66. <?php $count2++; ?>
  67. <section class="cat-box column2 <?php if($count2 == 2) { echo 'last-column'; $count2=0; } ?>">
  68. <div class="cat-box-title">
  69. <h2><?php echo $box_title ; ?></h2>
  70. <div class="stripe-line"></div>
  71. </div><!-- post-thumbnail /-->
  72. <div class="cat-box-content">
  73. <?php if($cat_query->have_posts()): ?>
  74. <ul>
  75. <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
  76. <?php if($count == 1) : ?>
  77. <li <?php tie_post_class('first-news'); ?>>
  78. <div class="inner-content">
  79. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  80. <div class="post-thumbnail">
  81. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  82. <?php tie_thumb( 'tie-medium' ); ?>
  83. <span class="overlay-icon"></span>
  84. </a>
  85. </div><!-- post-thumbnail /-->
  86. <?php endif; ?>
  87. <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>
  88. <div class="entry">
  89. <?php tie_excerpt_home() ?>
  90. <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
  91. </div>
  92. </div>
  93. </li><!-- .first-news -->
  94. <?php else: ?>
  95. <li <?php tie_post_class(); ?>>
  96. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  97. <div class="post-thumbnail">
  98. <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>
  99. </div><!-- post-thumbnail /-->
  100. <?php endif; ?>
  101. <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>
  102. <div class="entry">
  103. <?php tie_excerpt_home() ?>
  104. </div>
  105. </li>
  106. <?php endif; ?>
  107. <?php endwhile;?>
  108. </ul>
  109. <?php endif; ?>
  110. </div><!-- .cat-box-content /-->
  111. </section> <!-- Two Columns -->
  112. <?php elseif( $home_layout == '1c' ): //************** 1C ****************************************************** ?>
  113. <section class="cat-box wide-box">
  114. <div class="cat-box-title">
  115. <h2><?php echo $box_title ; ?></h2>
  116. <div class="stripe-line"></div>
  117. </div><!-- post-thumbnail /-->
  118. <div class="cat-box-content">
  119. <?php if($cat_query->have_posts()): ?>
  120. <ul>
  121. <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
  122. <?php if($count == 1) : ?>
  123. <li <?php tie_post_class( 'first-news' ); ?>>
  124. <div class="inner-content">
  125. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  126. <div class="post-thumbnail">
  127. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  128. <?php tie_thumb( 'tie-large' ); ?>
  129. <span class="overlay-icon"></span>
  130. </a>
  131. </div><!-- post-thumbnail /-->
  132. <?php endif; ?>
  133. <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>
  134. <div class="entry">
  135. <?php tie_excerpt_home() ?>
  136. <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
  137. </div>
  138. </div>
  139. </li><!-- .first-news -->
  140. <?php else: ?>
  141. <li <?php tie_post_class(); ?>>
  142. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  143. <div class="post-thumbnail">
  144. <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>
  145. </div><!-- post-thumbnail /-->
  146. <?php endif; ?>
  147. <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>
  148. <div class="entry">
  149. <?php tie_excerpt_home() ?>
  150. </div>
  151. </li>
  152. <?php endif; ?>
  153. <?php endwhile;?>
  154. </ul>
  155. <div class="clear"></div>
  156. <?php endif; ?>
  157. </div><!-- .cat-box-content /-->
  158. </section><!-- Wide Box -->
  159. <?php else : //************** list ********************************************************************************** ?>
  160. <section class="cat-box list-box">
  161. <div class="cat-box-title">
  162. <h2><?php echo $box_title ; ?></h2>
  163. <div class="stripe-line"></div>
  164. </div><!-- post-thumbnail /-->
  165. <div class="cat-box-content">
  166. <?php if($cat_query->have_posts()): ?>
  167. <ul>
  168. <?php while ( $cat_query->have_posts() ) : $cat_query->the_post(); $count ++ ;?>
  169. <?php if($count == 1) : ?>
  170. <li <?php tie_post_class( 'first-news' ); ?>>
  171. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  172. <div class="post-thumbnail">
  173. <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'tie' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
  174. <?php tie_thumb( 'tie-medium' ); ?>
  175. <span class="overlay-icon"></span>
  176. </a>
  177. </div><!-- post-thumbnail /-->
  178. <?php endif; ?>
  179. <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>
  180. <div class="entry">
  181. <?php tie_excerpt_home() ?>
  182. <a class="more-link" href="<?php the_permalink() ?>"><?php _e( 'Read More &raquo;', 'tie' ) ?></a>
  183. </div>
  184. </li><!-- .first-news -->
  185. <?php else: ?>
  186. <li <?php tie_post_class( 'other-news' ); ?>>
  187. <?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
  188. <div class="post-thumbnail">
  189. <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>
  190. </div><!-- post-thumbnail /-->
  191. <?php endif; ?>
  192. <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>
  193. <div class="entry">
  194. <?php tie_excerpt_home() ?>
  195. </div>
  196. </li>
  197. <?php endif; ?>
  198. <?php endwhile;?>
  199. </ul>
  200. <div class="clear"></div>
  201. <?php endif; ?>
  202. </div><!-- .cat-box-content /-->
  203. </section><!-- List Box -->
  204. <?php endif; ?>
  205. <?php } ?>