Advertisement
johnbentwin

Upcoming Section

Dec 13th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.40 KB | None | 0 0
  1. <h1>Upcoming</h1>
  2.      
  3.       <?php
  4.       for ($i=0; $i<10; $i++) {
  5.       $thedate = strtotime ( '+'.$i.' day' , strtotime ( $today ) ) ;
  6.       $thedate = date ( 'Y-m-d H:i' , $thedate );
  7.                
  8.       $thedaytext = strtotime ( '+'.$i.' day' , strtotime ( $todaytext ) ) ;
  9.       $thedaytext = date ( 'l' , $thedaytext );
  10.      
  11.       $thedatetext = strtotime ( '+'.$i.' day' , strtotime ( $todaydatetext ) ) ;
  12.       $thedatetext = date ( 'F j' , $thedatetext );
  13.                
  14.       $future = strtotime ( '+24 hours' , strtotime ( $thedate ) ) ;
  15.       $future = date ( 'Y-m-d H:i' , $future );
  16.       $times = array();  // put before the $event_query and seems to work
  17.                
  18.       $args = array(
  19.            'post_type' => 'event',
  20.            'orderby'     => 'meta_value',
  21.            'order'       => 'asc',
  22.            'meta_query' => array(
  23.            'relation' => 'OR',
  24.               array(
  25.                   'key' => 'opening_time',
  26.                   'value' => array($today,$future),
  27.                   'compare' => 'BETWEEN',
  28.                   'type' => 'DATE'
  29.               ),
  30.               array(
  31.                   'key' => 'artist_talk_time',
  32.                   'value' => array($today,$future),
  33.                   'compare' => 'BETWEEN',
  34.                   'type' => 'DATE'
  35.               ),
  36.               array(
  37.                   'key' => 'closing_time',
  38.                   'value' => array($today,$future),
  39.                   'compare' => 'BETWEEN',
  40.                   'type' => 'DATE'
  41.               ),
  42.               array(
  43.                   'key' => 'special_event_time',
  44.                   'value' => array($today,$future),
  45.                   'compare' => 'BETWEEN',
  46.                   'type' => 'DATE' 
  47.               )
  48.           )
  49.       );
  50.      
  51.       $event_query = new WP_Query( $args );
  52.       if ($event_query->have_posts()) : while ($event_query->have_posts()) :  $event_query->the_post();  
  53.          
  54.       $keys = array('opening_time', 'closing_time', 'artist_talk_time', 'special_event_time');
  55.       $custom_field_keys = get_post_custom_keys();
  56.          
  57.       foreach ($custom_field_keys as $custom_field_key) {
  58.          if (in_array($custom_field_key, $keys)) {   
  59.               $custom_field_value = get_post_meta($post->ID, $custom_field_key, true);
  60.               if ($custom_field_value >= $thedate && $custom_field_value <= $future) {
  61.                  $counttest++;
  62.                  $times[] = array($custom_field_value, $post->ID, $custom_field_key);
  63.               }
  64.           }
  65.       }    
  66.      
  67.       endwhile;
  68.       ?>
  69.      
  70.       <ul>
  71.      
  72.       <?php
  73.       if ($counttest >0) {
  74.       ?>
  75.       <li>
  76.       <h1 class="upcoming_date">
  77.       <span class="total">
  78.       <?php
  79.           echo $counttest;
  80.           if ($counttest>=2) {
  81.               echo ' Events ';
  82.           } // end if ($totalevents>=2) function
  83.           if ($counttest<2) {
  84.               echo ' Event ';
  85.           }
  86.       ?>
  87.            
  88.       </span> <!-- end .total -->
  89.       <span class="day_sidebar">
  90.            
  91.       <?php
  92.           if ($thedate==$today) {
  93.               echo 'Today';
  94.           }
  95.           if ($thedate>$today) {
  96.               echo $thedaytext;
  97.           }
  98.       ?>
  99.            
  100.       </span> <!-- end .day -->
  101.       <span class="date_sidebar">
  102.      
  103.       <?php
  104.           echo $thedatetext;
  105.       ?>
  106.       </span><!-- end .date -->
  107.       </h1>
  108.       </li>
  109.      
  110.       <?php
  111.       }
  112.       endif;
  113.       $counttest=0;
  114.        
  115.       sort($times); // I changed the asort to sort here
  116.            
  117.            foreach ($times as $event) { $time_value = $event[0]; $post_id = $event[1]; $time_key = $event[2];  // changed the foreach here
  118.      
  119.           if ($time_key == 'opening_time') { ?>
  120.          
  121.           <li class="sidebar_event">
  122.           <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
  123.          
  124.           <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
  125.           <h3>Opening</h3>
  126.           <h4>
  127.          
  128.        <?php
  129.           if (get_post_meta($post_id,'event_venue', true) != 'other') {
  130.               echo get_post_meta($post_id,'event_venue', true);
  131.               }
  132.           if (get_post_meta($post_id,'event_venue', true) == 'other') {
  133.               echo get_post_meta($post_id,'custom_event_venue', true);
  134.               }
  135.          
  136.        ?>
  137.        </h4>
  138.        <h5><?php $opening_time_formated = date($convertedtime, strtotime( get_post_meta($post_id,'opening_time', true)));
  139.             echo $opening_time_formated;?> </h5>
  140.                 <hr />
  141.           </li><!-- end .sidebar_event -->
  142.           <?php }
  143.          
  144.           else if ($time_key == 'artist_talk_time') { ?>
  145.                
  146.           <li class="sidebar_event">
  147.           <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
  148.          
  149.           <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
  150.           <h3>Artist Talk</h3>
  151.           <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
  152.           <h5><?php $artist_talk_time_formated = date($convertedtime, strtotime( get_post_meta($post_id,'artist_talk_time', true)));
  153.             echo $artist_talk_time_formated;?>  </h5>
  154.           <hr />
  155.           </li><!-- end .sidebar_event -->
  156.           <?php }
  157.            
  158.            else if ($time_key == 'closing_time') { ?>
  159.            <li class="sidebar_event">
  160.            <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
  161.          
  162.           <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
  163.           <h3>Closing</h3>
  164.           <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
  165.           <h5><?php echo get_post_meta($post_id,'closing_time', true);?> </h5>
  166.           <hr />
  167.           </li><!-- end .sidebar_event -->
  168.           <?php }
  169.          
  170.            else if ($time_key == 'special_event_time') { ?>
  171.            <li class="sidebar_event">
  172.            <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
  173.          
  174.           <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
  175.           <h3>Special Event</h3>
  176.           <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
  177.           <h5><?php $special_event_time_formated = date($convertedtime, strtotime( get_post_meta($post_id,'special_event_time', true)));
  178.             echo $special_event_time_formated;?></h5>
  179.           <hr />
  180.           </li><!-- end .sidebar_event -->
  181.           <?php }
  182.      
  183.            }
  184.          
  185.             rewind_posts();
  186.       ?>
  187.      
  188.       </ul>
  189.      
  190.       <?php
  191.        }
  192.        ?>
  193.        <br />
  194.       <br />
  195.       </div>
  196.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement