Guest User

Untitled

a guest
Apr 18th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.50 KB | None | 0 0
  1. <?php /* Template Name: Schedule */ ?>
  2.  
  3. <?php get_header(); ?>
  4.  
  5. <div id="main-content">
  6.  
  7. <?php $is_page_builder_used = et_pb_is_pagebuilder_used( get_the_ID() ); ?>
  8.  
  9. <?php if ( ! $is_page_builder_used ) : ?>
  10.  
  11.     <div class="container">
  12.         <div id="content-area" class="clearfix">
  13.             <div id="left-area">
  14.  
  15. <?php endif; ?>
  16.         <?php
  17.        
  18.         // Start the loop.
  19.         while ( have_posts() ) : the_post();
  20.  
  21.             // Include the page content template.
  22.             //get_template_part( 'template-parts/content', 'page' ); ?>
  23.            
  24.             <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  25.  
  26.                 <?php if ( ! $is_page_builder_used ) : ?>
  27.  
  28.                 <?php
  29.                     $thumb = '';
  30.  
  31.                     $width = (int) apply_filters( 'et_pb_index_blog_image_width', 1080 );
  32.  
  33.                     $height = (int) apply_filters( 'et_pb_index_blog_image_height', 675 );
  34.                     $classtext = 'et_featured_image';
  35.                     $titletext = get_the_title();
  36.                     $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  37.                     $thumb = $thumbnail["thumb"];
  38.  
  39.                     if ( 'on' === et_get_option( 'divi_page_thumbnails', 'false' ) && '' !== $thumb )
  40.                         print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height );
  41.                 ?>
  42.  
  43.                 <?php endif; ?>
  44.  
  45.                     <div class="entry-content">
  46.                     <?php
  47.                         the_content();
  48.  
  49.                         if ( ! $is_page_builder_used )
  50.                             wp_link_pages( array( 'before' => '<div class="page-links">' . esc_html__( 'Pages:', 'Divi' ), 'after' => '</div>' ) );
  51.                     ?>
  52.                     </div> <!-- .entry-content -->
  53.  
  54.                 <?php
  55.                     if ( ! $is_page_builder_used && comments_open() && 'on' === et_get_option( 'divi_show_pagescomments', 'false' ) ) comments_template( '', true );
  56.                 ?>
  57.  
  58.                 </article> <!-- .et_pb_post -->
  59.            
  60.             <?php $days_id = get_field_objects(164);
  61.            
  62.             $args = array(
  63.                 'post_type' => 'scheduled_shows',
  64.                 'post_status' => 'publish',
  65.                 'posts_per_page' => -1,
  66.             );
  67.             $days = get_posts($args);
  68.             error_reporting(E_ALL);
  69.             ini_set('display_errors','On');
  70.            
  71.  
  72.       // Sort shows into an array by day
  73.       $days_shows = array();
  74.       foreach ($days as $show) {
  75.         $day = get_field('days', $show->ID);
  76.         $repeat_day = get_field('repeat_days', $show->ID);
  77.         // Add time information to the show object
  78.         $show->times = array(
  79.           'start' => get_field('start_time', $show->ID),
  80.           'end' => get_field('end_time', $show->ID),
  81.         );
  82.         $repeat_show->times = array(
  83.           'start' => get_field('repeat_start_time', $show->ID),
  84.           'end' => get_field('repeat_end_time', $show->ID),
  85.         );
  86.         if (!empty($day)) {
  87.           $days_shows[$day[0]][] = $show;
  88.         } elseif (!empty($repeat_day)) {
  89.           $days_shows[$repeat_day[0]][] = $repeat_show;
  90.         }
  91.       }
  92.  
  93.       // Sort the shows by start time
  94.       foreach ($days_shows as $day => $shows) {
  95.         usort($days_shows[$day], function($a, $b) {
  96.           list($hour_a, $minute_a) =
  97.             array_map('intval', explode(':', $a->times['start']));
  98.           list($hour_b, $minute_b) =
  99.             array_map('intval', explode(':', $b->times['start']));
  100.           if ($hour_a === $hour_b) {
  101.             return $minute_a < $minute_b ? -1 : 1;
  102.           } else {
  103.             return $hour_a < $hour_b ? -1 : 1;
  104.           }
  105.         });
  106.       }
  107.      
  108.       foreach ($days_shows as $repeat_day => $repeat_shows) {
  109.         usort($days_shows[$repeat_day], function($a, $b) {
  110.           list($hour_a, $minute_a) =
  111.             array_map('intval', explode(':', $a->times['start']));
  112.           list($hour_b, $minute_b) =
  113.             array_map('intval', explode(':', $b->times['start']));
  114.           if ($hour_a === $hour_b) {
  115.             return $minute_a < $minute_b ? -1 : 1;
  116.           } else {
  117.             return $hour_a < $hour_b ? -1 : 1;
  118.           }
  119.         });
  120.       }
  121.  
  122.       // Create tabbed output shortcode
  123.       ob_start();
  124.       ?>
  125.       [tabs slidertype="top tabs"]
  126.         [tabcontainer]
  127.           <?php // Add tabs for each day ?>
  128.           <?php foreach ($days_id['days']['choices'] as $key => $value): ?>
  129.             [tabtext]<?php print $value; ?>[/tabtext]
  130.           <?php endforeach; ?>
  131.         [/tabcontainer]
  132.         [tabcontent]
  133.           <?php // Add tab contents ?>
  134.           <?php foreach ($days_id['days']['choices'] as $key => $value): ?>
  135.             [tab]
  136.               <?php if (!isset($days_shows[$key])): ?>
  137.                 <p class="no-shows"><?php _e('No shows scheduled for this day'); ?></p>
  138.               <?php else: ?>
  139.                 <ul class="schedule-day">
  140.                   <?php foreach ($days_shows[$key] as $show) {
  141.                     $GLOBALS['post'] = $show;
  142.                     setup_postdata($GLOBALS['post']);
  143.                     print '<li class="schedule-show">';
  144.                     print get_template_part('schedule', $show->post_type);
  145.                     print '</li>';
  146.                     wp_reset_postdata();
  147.                   } ?>
  148.                 </ul>
  149.               <?php endif; ?>
  150.             [/tab]
  151.           <?php endforeach; ?>
  152.           <?php foreach ($days_id['repeat_days']['choices'] as $key => $value): ?>
  153.             [tab]
  154.               <?php if (!isset($days_shows[$key])): ?>
  155.                 <p class="no-shows"><?php _e('No shows scheduled for this day'); ?></p>
  156.               <?php else: ?>
  157.                 <ul class="schedule-day">
  158.                   <?php foreach ($days_shows[$key] as $repeat_show) {
  159.                     $GLOBALS['post'] = $repeat_show;
  160.                     setup_postdata($GLOBALS['post']);
  161.                     print '<li class="schedule-show">';
  162.                     print get_template_part('schedule', $repeat_show->post_type);
  163.                     print '</li>';
  164.                     wp_reset_postdata();
  165.                   } ?>
  166.                 </ul>
  167.               <?php endif; ?>
  168.             [/tab]
  169.           <?php endforeach; ?>
  170.         [/tabcontent]
  171.       [/tabs]
  172.       <?php
  173.  
  174.       // Output the tabbed schedule
  175.       print '<div class="schedule">' . do_shortcode(ob_get_clean()) . '</div>';
  176.  
  177.  
  178.             // If comments are open or we have at least one comment, load up the comment template.
  179.             if ( comments_open() || get_comments_number() ) {
  180.                 comments_template();
  181.             }
  182.  
  183.             // End of the loop.
  184.         endwhile;
  185.         ?>
  186.  
  187.     <?php if ( ! $is_page_builder_used ) : ?>
  188.  
  189.             </div> <!-- #left-area -->
  190.  
  191.             <?php get_sidebar(); ?>
  192.         </div> <!-- #content-area -->
  193.     </div> <!-- .container -->
  194.  
  195. <?php endif; ?>
  196.  
  197. </div> <!-- #main-content -->
  198.  
  199. <?php get_footer(); ?>
Add Comment
Please, Sign In to add comment