Advertisement
johnbentwin

Events Page Loop

Dec 13th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.60 KB | None | 0 0
  1.       <?php // This is the loop for quering an individual page's events and upcoming events
  2.       $todaysDate = date('Y/m/d'); // Get today's date in the right format
  3.       $today = date("Y-m-d 00:00");  //set today's date for upcomming events sidebar
  4.       $lastWeek = date("Y-m-d", strtotime("-7 days"));
  5.       $nextWeek = date("Y/m/d", strtotime("+7 days"));
  6.       $todaytext = date("l"); // define $todaytext with written out days for upcomming events sidebar
  7.       $todaydatetext = date("F j"); // define $todaydatetext as written month and number date for upcomming events sidebar
  8.       $convertedtime = "g:i"; // convert to 12 hour clock and minutes for upcomming events sidebar
  9.      
  10.       $eventsloop = new WP_Query('post_type=event&location=' . $whatCity .'&meta_key=end_date&meta_compare=>=&meta_value=' . $todaysDate . '&orderby=meta_value&order=ASC'); // Displays the events that have not ended yet
  11.      
  12.       $featured_args = array(
  13.            'post_type' => 'event',
  14.            'posts_per_page' => '1',
  15.            'orderby'     => 'rand',
  16.            'meta_query' => array(
  17.            'relation' => 'AND',
  18.               array(
  19.                   'key' => 'featured_event',
  20.                   'value' => 'on',
  21.                   'compare' => '=='
  22.               ),
  23.               array(
  24.                   'key' => 'end_date',
  25.                   'value' => $todaysDate,
  26.                   'compare' => '>=',
  27.                   'type' => 'DATE' 
  28.               )
  29.           )
  30.       );
  31.      
  32.      
  33.       $featured_event_query = new WP_Query( $featured_args );
  34.       if ($featured_event_query->have_posts()) : while($featured_event_query->have_posts()) : $featured_event_query->the_post(); // begin the loop after sorting the posts by location date and removing old end dates
  35.       ?>
  36.      
  37.       <div class="recommended_event">
  38.       <h1>We Recommend</h1>
  39.       <?php
  40.       ?>
  41.       <h3><?php
  42.           if (get_post_meta($post->ID,'event_venue', true) != 'other') {
  43.               echo get_post_meta($post->ID,'event_venue', true);
  44.               }
  45.           if (get_post_meta($post->ID,'event_venue', true) == 'other') {
  46.               echo get_post_meta($post->ID,'custom_event_venue', true);
  47.               }
  48.       ?></h3>
  49.      
  50.       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title('<h2>', '</h2>'); ?></a>
  51.       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo get_the_post_thumbnail($post_id, 'featured_events'); ?></a>
  52.       <?php endwhile;?>
  53.       </div><!-- end .recommended_event-->
  54.      
  55.       <?php endif; ?>
  56.      
  57.      
  58.       <h1 class="ongoing_events">Ongoing</h1>
  59.       <?php
  60.       while($eventsloop->have_posts()) : $eventsloop->the_post(); // begin the loop after sorting the posts by location date and removing old end dates
  61.       ?>
  62.       <div class="ongoing_event">
  63.       <div class="row">
  64.       <div class="grid_4">
  65.       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title('<h2>', '</h2>'); ?></a>
  66.       <a href=""><h3><?php  
  67.      
  68.           if (get_post_meta(get_the_ID(),'event_venue', true) != 'other') {
  69.               echo get_post_meta(get_the_ID(),'event_venue', true);
  70.               }
  71.           if (get_post_meta(get_the_ID(),'event_venue', true) == 'other') {
  72.               echo get_post_meta(get_the_ID(),'custom_event_venue', true);
  73.               }
  74.       ?></h3></a>  
  75.      
  76.       <?php
  77.      
  78.       $venue = get_post_meta( $post->ID, 'event_venue', true );
  79.       echo get_related_event_data( $venue, 'address' );
  80.       echo get_related_event_data( $venue, 'address' );
  81.       echo get_related_event_data( $venue, 'address' ); ?>
  82.      
  83.       <?php // Format the running dates
  84.       $startdate = get_post_meta($post->ID, 'start_date', true);
  85.       $enddate = get_post_meta($post->ID, 'end_date', true);
  86.       $writestart = preg_split ( '/\//', $startdate );
  87.       $writeend = preg_split ( '/\//', $enddate );
  88.       ?>
  89.      
  90.       <h4>
  91.       <?php // and print nicely
  92.       if (get_post_meta($post->ID,'end_date', true) <= $nextWeek) {
  93.           echo '<span class="last_chance">Last Chance: </span>';   
  94.       }
  95.       echo date('F j', mktime( 0, 0, 0, $writestart[1], $writestart[2], $writestart[0] ) );
  96.       echo ' through ';
  97.       echo date('F j, Y', mktime( 0, 0, 0, $writeend[1], $writeend[2], $writeend[0] ) );
  98.       ?>
  99.       </h4>    
  100.      
  101.       <?php // Check if Opening or Closing dates exist and echo the information    
  102.       $convertedtime2 = "F j, Y | g:i a"; // convert to 12 hour clock and minutes      
  103.       $opening_time_formated = date($convertedtime2, strtotime( get_post_meta($post->ID,'opening_time', true)));   
  104.       $closing_time_formated = date($convertedtime2, strtotime( get_post_meta($post->ID,'closing_time', true)));   
  105.       $end_date_formated = date('F j, Y', mktime( 0, 0, 0, $writeend[1], $writeend[2], $writeend[0] ) );
  106.      
  107.       ?>
  108.      
  109.       <?php
  110.      
  111.      
  112.       if (get_post_meta($post->ID,'opening_time', true) >= $today) {                   
  113.           echo '<h5><span class="strong">Opening: </span>'.$opening_time_formated .'</h5>';            
  114.       }
  115.       if (get_post_meta($post->ID,'closing_time', true) >= $today) {
  116.           echo '<h5><span class="strong">Closing: </span>'.$closing_time_formated .'</h5>';
  117.       }
  118.       if (get_post_meta($post->ID,'artist_talk_time', true) >= $today) {
  119.           echo '<h5><span class="strong">Artist Talk: </span>'.$closing_time_formated .'</h5>';
  120.       }
  121.      
  122.      
  123.       ?>
  124.      
  125.       <?php
  126.      
  127.       $today = date("Y-m-d");
  128.       ?>
  129.      
  130.       </div><!-- end .grid_4-->
  131.       <div class="grid_4">
  132.      
  133.       <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo get_the_post_thumbnail($post_id, 'half_postcard'); ?></a>
  134.      
  135.       </div> <!-- end .grid_4-->
  136.       </div><!-- end .row-->               
  137.       </div><!-- end .ongoing_event-->
  138.       <?php endwhile; ?>
  139.      
  140.       </div> <!-- end .grid_8-->
  141.      
  142.       <div class="grid_4">
  143.      
  144.       <div class="row">
  145.      
  146.      
  147.       <div class="sidebar_upcoming_events">
  148.       <div id="upcoming-events" class="module module-upcoming">
  149.      
  150.       <h1>Upcoming</h1>
  151.      
  152.       <?php
  153.       for ($i=0; $i<10; $i++) {
  154.       $thedate = strtotime ( '+'.$i.' day' , strtotime ( $today ) ) ;
  155.       $thedate = date ( 'Y-m-d H:i' , $thedate );
  156.                
  157.       $thedaytext = strtotime ( '+'.$i.' day' , strtotime ( $todaytext ) ) ;
  158.       $thedaytext = date ( 'l' , $thedaytext );
  159.      
  160.       $thedatetext = strtotime ( '+'.$i.' day' , strtotime ( $todaydatetext ) ) ;
  161.       $thedatetext = date ( 'F j' , $thedatetext );
  162.                
  163.       $future = strtotime ( '+24 hours' , strtotime ( $thedate ) ) ;
  164.       $future = date ( 'Y-m-d H:i' , $future );
  165.       $times = array();  // put before the $event_query and seems to work
  166.                
  167.       $args = array(
  168.            'post_type' => 'event',
  169.            'orderby'     => 'meta_value',
  170.            'order'       => 'asc',
  171.            'meta_query' => array(
  172.            'relation' => 'OR',
  173.               array(
  174.                   'key' => 'opening_time',
  175.                   'value' => array($today,$future),
  176.                   'compare' => 'BETWEEN',
  177.                   'type' => 'DATE'
  178.               ),
  179.               array(
  180.                   'key' => 'artist_talk_time',
  181.                   'value' => array($today,$future),
  182.                   'compare' => 'BETWEEN',
  183.                   'type' => 'DATE'
  184.               ),
  185.               array(
  186.                   'key' => 'closing_time',
  187.                   'value' => array($today,$future),
  188.                   'compare' => 'BETWEEN',
  189.                   'type' => 'DATE'
  190.               ),
  191.               array(
  192.                   'key' => 'special_event_time',
  193.                   'value' => array($today,$future),
  194.                   'compare' => 'BETWEEN',
  195.                   'type' => 'DATE' 
  196.               )
  197.           )
  198.       );
  199.      
  200.       $event_query = new WP_Query( $args );
  201.       if ($event_query->have_posts()) : while ($event_query->have_posts()) :  $event_query->the_post();  
  202.          
  203.       $keys = array('opening_time', 'closing_time', 'artist_talk_time', 'special_event_time');
  204.       $custom_field_keys = get_post_custom_keys();
  205.          
  206.       foreach ($custom_field_keys as $custom_field_key) {
  207.          if (in_array($custom_field_key, $keys)) {   
  208.               $custom_field_value = get_post_meta($post->ID, $custom_field_key, true);
  209.               if ($custom_field_value >= $thedate && $custom_field_value <= $future) {
  210.                  $counttest++;
  211.                  $times[] = array($custom_field_value, $post->ID, $custom_field_key);
  212.               }
  213.           }
  214.       }    
  215.      
  216.       endwhile;
  217.       ?>
  218.      
  219.       <ul>
  220.      
  221.       <?php
  222.       if ($counttest >0) {
  223.       ?>
  224.       <li>
  225.       <h1 class="upcoming_date">
  226.       <span class="total">
  227.       <?php
  228.           echo $counttest;
  229.           if ($counttest>=2) {
  230.               echo ' Events ';
  231.           } // end if ($totalevents>=2) function
  232.           if ($counttest<2) {
  233.               echo ' Event ';
  234.           }
  235.       ?>
  236.            
  237.       </span> <!-- end .total -->
  238.       <span class="day_sidebar">
  239.            
  240.       <?php
  241.           if ($thedate==$today) {
  242.               echo 'Today';
  243.           }
  244.           if ($thedate>$today) {
  245.               echo $thedaytext;
  246.           }
  247.       ?>
  248.            
  249.       </span> <!-- end .day -->
  250.       <span class="date_sidebar">
  251.      
  252.       <?php
  253.           echo $thedatetext;
  254.       ?>
  255.       </span><!-- end .date -->
  256.       </h1>
  257.       </li>
  258.      
  259.       <?php
  260.       }
  261.       endif;
  262.       $counttest=0;
  263.        
  264.       sort($times); // I changed the asort to sort here
  265.            
  266.            foreach ($times as $event) { $time_value = $event[0]; $post_id = $event[1]; $time_key = $event[2];  // changed the foreach here
  267.      
  268.           if ($time_key == 'opening_time') { ?>
  269.          
  270.           <li class="sidebar_event">
  271.           <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>
  272.          
  273.           <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>
  274.           <h3>Opening</h3>
  275.           <h4>
  276.          
  277.        <?php
  278.           if (get_post_meta($post_id,'event_venue', true) != 'other') {
  279.               echo get_post_meta($post_id,'event_venue', true);
  280.               }
  281.           if (get_post_meta($post_id,'event_venue', true) == 'other') {
  282.               echo get_post_meta($post_id,'custom_event_venue', true);
  283.               }
  284.          
  285.        ?>
  286.        </h4>
  287.        <h5><?php $opening_time_formated = date($convertedtime, strtotime( get_post_meta($post_id,'opening_time', true)));
  288.             echo $opening_time_formated;?> </h5>
  289.                 <hr />
  290.           </li><!-- end .sidebar_event -->
  291.           <?php }
  292.          
  293.           else if ($time_key == 'artist_talk_time') { ?>
  294.                
  295.           <li class="sidebar_event">
  296.           <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>
  297.          
  298.           <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>
  299.           <h3>Artist Talk</h3>
  300.           <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
  301.           <h5><?php $artist_talk_time_formated = date($convertedtime, strtotime( get_post_meta($post_id,'artist_talk_time', true)));
  302.             echo $artist_talk_time_formated;?>  </h5>
  303.           <hr />
  304.           </li><!-- end .sidebar_event -->
  305.           <?php }
  306.            
  307.            else if ($time_key == 'closing_time') { ?>
  308.            <li class="sidebar_event">
  309.            <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>
  310.          
  311.           <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>
  312.           <h3>Closing</h3>
  313.           <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
  314.           <h5><?php echo get_post_meta($post_id,'closing_time', true);?> </h5>
  315.           <hr />
  316.           </li><!-- end .sidebar_event -->
  317.           <?php }
  318.          
  319.            else if ($time_key == 'special_event_time') { ?>
  320.            <li class="sidebar_event">
  321.            <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>
  322.          
  323.           <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>
  324.           <h3>Special Event</h3>
  325.           <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
  326.           <h5><?php $special_event_time_formated = date($convertedtime, strtotime( get_post_meta($post_id,'special_event_time', true)));
  327.             echo $special_event_time_formated;?></h5>
  328.           <hr />
  329.           </li><!-- end .sidebar_event -->
  330.           <?php }
  331.      
  332.            }
  333.          
  334.             rewind_posts();
  335.       ?>
  336.      
  337.       </ul>
  338.      
  339.       <?php
  340.        }
  341.        ?>
  342.        <br />
  343.       <br />
  344.       </div>
  345.      
  346.       </div><!-- end .sidebar_upcoming_events-->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement