Advertisement
rejuancse

feather-light

Apr 24th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.26 KB | None | 0 0
  1. <?php
  2. /*
  3. * Event Shortcode.
  4. */
  5.  
  6. add_shortcode( 'custom_posts_event', 'custom_posts_event_func' );
  7. function custom_posts_event_func( $atts ){
  8.  
  9.   global $post;
  10.   $default = array(
  11.     'type'            => 'event',
  12.     'post_type'       => '',
  13.     'limit'           => 10,
  14.     'status'          => 'publish'
  15.   );
  16.   $r = shortcode_atts( $default, $atts );
  17.   extract( $r );
  18.  
  19.   if( empty($post_type) )
  20.     $post_type = $type;
  21.  
  22.   $return = $limit_post = '';
  23.  
  24.   $post_type_ob = get_post_type_object( $post_type );
  25.  
  26.   if( !$post_type_ob )
  27.     return '<div class="warning"><p>No such post type <em>' . $post_type . '</em> found.</p></div>';
  28.  
  29.   # Column Order.
  30.  $order_list = get_option('event_post_order');
  31.   if ( ! $order_list)
  32.   $order_list = 'desc';
  33.  
  34.   $args = array(
  35.     'post_type'           => $post_type,
  36.     'order'             => esc_attr($order_list),
  37.     'numberposts'         => $limit,
  38.     'post_status'         => $status,
  39.     'posts_per_page'    => $limit_post,
  40.   );
  41.  
  42.   $posts = get_posts( $args );
  43.  
  44.   # Number of Column
  45.  $numofcolumn = get_option('num_custom_settings');
  46.   if ( ! $numofcolumn)
  47.   $numofcolumn = '4';
  48.  
  49.  
  50.   $count = 1;
  51.   if( count($posts) ):
  52.  
  53.     $return .= '<div class="event-post-wrapper">';
  54.     foreach( $posts as $post ): setup_postdata( $post );
  55.  
  56.     $datetime   = get_post_meta(get_the_ID(), 'cpt_event_start_datetime', true);
  57.     # Event Countdown script. ?>
  58.  
  59.     <script type="text/javascript">
  60.         jQuery(function($) {
  61.             $('#countdown-timer'+<?php echo $count; ?>+'').countdown("<?php echo str_replace('-', '/', $datetime); ?>", function(event) {
  62.                 $(this).html(event.strftime('<div class="countdown-section"><span class="countdown-amount first-item countdown-days">%-D </span><span class="countdown-period">%!D: .<?php echo esc_html__("DAY", "custom-post"); ?>,<?php echo esc_html__("DAYS", "custom-post"); ?>;</span></div><div class="countdown-section"><span class="countdown-amount countdown-hours">%-H </span><span class="countdown-period">%!H:<?php echo esc_html__("HOUR", "custom-post"); ?>,<?php echo esc_html__("HOURS", "custom-post"); ?>;</span></div><div class="countdown-section"><span class="countdown-amount countdown-minutes">%-M </span><span class="countdown-period">%!M:<?php echo esc_html__("MINUTE", "custom-post"); ?>,<?php echo esc_html__("MINUTES", "custom-post"); ?>;</span></div><div class="countdown-section"><span class="countdown-amount countdown-seconds">%-S </span><span class="countdown-period">%!S:<?php echo esc_html__("SECOND", "custom-post"); ?>,<?php echo esc_html__("SECONDS", "custom-post"); ?>;</span></div>'));
  63.             });
  64.         });
  65.     </script>
  66.  
  67. <?php
  68.     $return .= '<div class="evenst-content-arapper cp-col-'.esc_attr($numofcolumn).'">';
  69.  
  70.     $return .= '<div class="event-wrapper">';
  71.       if ( has_post_thumbnail() ) {
  72.           $img  = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'cpt-event' );
  73.           $return .= '<div class="event-img">';
  74.           $return .= '<a data-featherlight="#fl1'.$post->ID.'" href="#">';
  75.           $return .= '<img class="img-responsive" src="'.esc_url( $img[0] ).'" alt="'. get_the_title() .'" >';
  76.           $return .= '</a>';
  77.           $return .= '</div>';
  78.       }
  79.  
  80.       $return .= '<div class="counstdown-text-wrap">';
  81.       $return .= '<h3 class="countsdown-timer-title">'.date_i18n("F j, Y", strtotime($datetime)).'</h3>';
  82.       $return .= '<h3 class="countdsown-timer-subtitle"><a data-featherlight="#fl1'.$post->ID.'" href="#">'. get_the_title() .'</a></h3>';
  83.       $return .= '<div id="countdown-timer'. $count .'"></div>';
  84.       $return .= '</div>';
  85.  
  86.     $return .= '</div>';
  87.     $return .= '</div>';
  88.  
  89.  
  90. $start_date   = get_post_meta(get_the_ID(), 'cpt_event_start_datetime', true);
  91. $endtime      = get_post_meta(get_the_ID(), 'cpt_event_end_datetime', true);
  92. #Feather Light HTML tag
  93. $return.='<div class="lightbox" id="fl1'.$post->ID.'">
  94.            <div class="tup-popup-area">
  95.              <div class="tup-popup-left"><img class="img-responsive" src="'.esc_url( $img[0] ).'" alt="'. get_the_title() .'" ></div>
  96.              <div class="tup-popup-right">
  97.                <h3>'. get_the_title() .'</h3>
  98.                <p>'. get_the_content() .'</p>
  99.  
  100.                <div class="event-date-time">
  101.  
  102.                <div class="cpt-event-datetime">
  103.                  <h3>Event Date</h3>
  104.                  <div class="event-date">
  105.                    <span class="event-date">'.date_i18n(get_option( 'date_format' ), strtotime($start_date)).' - '.date_i18n(get_option( 'date_format' ), strtotime($endtime)).' </span>
  106.                    
  107.                  </div>
  108.                </div>
  109.  
  110.                <div class="cpt-event-timedate">
  111.                  <h3>Event Time</h3>
  112.                  <div class="event-time">
  113.                    <span class="event-time">'. date_i18n("h:i A", strtotime($start_date)).' - '.date_i18n("H:i A", strtotime($endtime)).' </span>
  114.                  </div>
  115.                </div>
  116.                </div> <!--/.event-date-->
  117.  
  118.        </div>
  119.    </div>
  120. </div>';
  121. #End HTML tag
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.     $count++;
  134.     endforeach;
  135.     wp_reset_postdata();
  136.     $return .= '</div>';
  137.   else :
  138.     $return .= '<p>No posts found.</p>';
  139.   endif;
  140.  
  141.   return $return;
  142. }
  143. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement