Advertisement
Guest User

Untitled

a guest
Feb 19th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. <?php
  2. $today = getdate();
  3.  
  4. if (array_key_exists("sortby", $_GET) === true)
  5. {
  6. $newQuery = sortIt($_GET['sortby']);
  7.  
  8. } elseif(array_key_exists('date', $_GET)) {
  9. $newQuery = new WP_Query(
  10. array(
  11. 'meta_key' => 'details_start_date',
  12. 'orderby' => 'meta_value',
  13. 'order'=> 'ASC',
  14. 'cat' => '5',
  15. 'posts_per_page' => '5',
  16. 'post_status'=>'future',
  17. 'paged'=>$paged,
  18. 'meta_query' => array(
  19. array(
  20. 'key' => 'details_start_date',
  21. 'value' => $_GET['date'],
  22. 'compare' => '=',
  23. )
  24. ),
  25.  
  26. )
  27. );
  28. }
  29. else{
  30. $newQuery = new WP_Query(
  31. array(
  32. 'meta_key' => 'details_start_date',
  33. 'orderby' => 'meta_value',
  34. 'order'=> 'ASC',
  35. 'cat' => '5',
  36. 'posts_per_page' => '5',
  37. 'paged'=>$paged,
  38. 'post_status'=>'future',
  39. 'meta_query' => array(
  40. array(
  41. 'key' => 'details_start_date',
  42. 'value' => date('Y-m-d'),
  43. 'compare' => '>=',
  44. )
  45. ),
  46.  
  47. )
  48. );
  49. $btnall = "";
  50. $btnupcoming = "btn-upcoming";
  51. $btnpast = "";
  52. }
  53. function sortIt($sortType)
  54. {
  55. global $wp_query;
  56. global $btnall;
  57. global $btnupcoming;
  58. global $btnpast;
  59. $cat_ID = get_query_var('cat');
  60.  
  61. if (strcmp($sortType, 'past') == 0 )
  62. {
  63. $newQuery = new WP_Query(
  64. array(
  65. 'meta_key' => 'details_start_date',
  66. 'orderby' => 'meta_value',
  67. 'order'=> 'DESC',
  68. 'cat' => '5',
  69. 'posts_per_page' => '5',
  70. 'post_status'=>'publish',
  71. 'paged'=>$paged,
  72. 'meta_query' => array(
  73. array(
  74. 'key' => 'details_start_date',
  75. 'value' => date('Y-m-d'),
  76. 'compare' => '<',
  77. )
  78. ),
  79. )
  80. );
  81.  
  82. $btnall = "";
  83. $btnupcoming = "";
  84. $btnpast = "btn-past";
  85. }
  86.  
  87. if (strcmp($sortType, 'upcoming') == 0 )
  88. {
  89. $newQuery = new WP_Query(
  90. array(
  91. 'meta_key' => 'details_start_date',
  92. 'orderby' => 'meta_value',
  93. 'order'=> 'ASC',
  94. 'cat' => '5',
  95. 'posts_per_page' => '5',
  96. 'post_status'=>'future',
  97. 'paged'=>$paged,
  98. 'meta_query' => array(
  99. array(
  100. 'key' => 'details_start_date',
  101. 'value' => date('Y-m-d'),
  102. 'compare' => '>=',
  103. )
  104. ),
  105. )
  106. );
  107. $btnall = "";
  108. $btnupcoming = "btn-upcoming";
  109. $btnpast = "";
  110. }
  111.  
  112. return $newQuery;
  113. }
  114. ?>
  115.  
  116. <?php get_header(); ?>
  117.  
  118. <div id="content" class="clearfix row-fluid">
  119. <div id="main" class="span12 clearfix" role="main">
  120. <div class="main-content">
  121. <div class="content-banner">
  122. <img src="<?php echo get_template_directory_uri();?>/images/events-banner.jpg" alt="" />
  123. </div>
  124. <div class="clearfix row-fluid">
  125. <div class="clearfix span8">
  126. <?php wp_reset_postdata(); ?>
  127.  
  128. <div class="btn-group">
  129. <a class="btn btn-default <?=$btnupcoming?>" href="<?php echo home_url(); ?>/events?sortby=upcoming" role="button">Upcoming</a>
  130.  
  131. <a class="btn btn-default <?=$btnpast?>" href="<?php echo home_url(); ?>/events?sortby=past" role="button">Past</a>
  132. </div>
  133. <br /><br />
  134. <?php if(array_key_exists('date', $_GET)):?>
  135. <h2>Events on <?php echo date('F d, Y', strtotime($_GET['date'])) ?></h2>
  136. <br/><br/>
  137. <?php endif;?>
  138. <?php $the_query = $newQuery; ?>
  139.  
  140. <?php if ($the_query->have_posts()): ?>
  141.  
  142. <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
  143. <?php
  144. $custom = get_post_custom();
  145. $custom_date = date('F d, Y', strtotime($custom['details_start_date'][0]));
  146. ?>
  147.  
  148. <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article">
  149.  
  150. <header>
  151. <h3 style="margin:0;line-height:35px;"><a style="color:#1e4667;" href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?> </a></h3>
  152. <time datetime="<?php echo $custom_date; ?>" pubdate><?php echo $custom_date; ?>
  153.  
  154. <?php if(!empty($custom['details_start_time'][0])):?>
  155. | <?php echo $custom['details_start_time'][0] ?>
  156. <?php endif;?>
  157. </time>
  158.  
  159. </header> <!-- end article header -->
  160.  
  161. <section class="post_content clearfix">
  162. <?php the_excerpt( __("Read more &raquo;","bonestheme") ); ?>
  163. </section> <!-- end article section -->
  164. </article> <!-- end article -->
  165. <?php endwhile; ?>
  166.  
  167. <?php else:?>
  168. <h4>Events could not be found...</h4>
  169. <?php endif;?>
  170. <?php
  171. $big = 999999999; // need an unlikely integer
  172.  
  173. echo paginate_links( array(
  174. 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  175. 'format' => '?paged=%#%',
  176. 'current' => max( 1, get_query_var('paged') ),
  177. 'total' => $the_query->max_num_pages
  178. ) );
  179. ?>
  180.  
  181. <?php if (function_exists('page_navi')) { // if expirimental feature is active ?>
  182.  
  183. <?php page_navi(); // use the page navi function ?>
  184.  
  185. <?php } else { // if it is disabled, display regular wp prev & next links ?>
  186. <nav class="wp-prev-next">
  187. <ul class="clearfix">
  188. <li class="prev-link"><?php next_posts_link(_e('&laquo; Older Entries', "bonestheme")) ?></li>
  189. <li class="next-link"><?php previous_posts_link(_e('Newer Entries &raquo;', "bonestheme")) ?></li>
  190. </ul>
  191. </nav>
  192. <?php } ?>
  193.  
  194. </div>
  195. <?php get_sidebar('events'); ?>
  196. </div>
  197. </div>
  198. </div> <!-- end #main -->
  199. </div> <!-- end #content -->
  200. </div> <!-- end #container -->
  201. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement