Advertisement
rejuancse

educon-event

Dec 22nd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.39 KB | None | 0 0
  1. <?php
  2. if ( ! defined( 'ABSPATH' ) ) {
  3.     exit; # Exit if accessed directly
  4. }
  5.  
  6. # Upcoming Events
  7. add_shortcode( 'educon_events', function($atts, $content = null){
  8.  
  9.     extract(shortcode_atts(array(
  10.         'layout'        => 'layout1',
  11.         'title'         => '',
  12.         'count'         => '3',
  13.         'event_cat'     => 'themeumall',
  14.         'order'         => 'DESC',
  15.         'class'         => '',
  16.         ), $atts));
  17.  
  18.     global $post;
  19.     $output = '';
  20.  
  21.  
  22.     if ( $layout == 'layout1' || $layout == 'layout2' ) {
  23.  
  24.         if( ( $event_cat == '' ) || ( $event_cat == 'themeumall' ) ){
  25.             $args = array(
  26.                 'post_type'         => 'event',
  27.                 'showposts'         => $count,
  28.                 'meta_type'         => 'DATETIME',
  29.                 'orderby'           => 'meta_value',
  30.                 'order'             => $order,
  31.                 'meta_key'          => 'themeum_start_datetime',
  32.                 'meta_value'        => date('Y-m-d h:i'),
  33.                 'meta_compare'      => '>=',
  34.                 'paged'             => get_query_var('paged')
  35.             );
  36.         } else{
  37.             $args = array(
  38.                 'post_type' => 'event',
  39.                 'showposts' => $count,
  40.                 'tax_query' => array(
  41.                     array(
  42.                         'taxonomy' => 'event-category',
  43.                         'field'    => 'slug',
  44.                         'terms'    => $event_cat,
  45.                     ),
  46.                 ),
  47.                 'meta_key'      => 'themeum_start_datetime',
  48.                 'meta_type'     => 'DATETIME',
  49.                 'orderby'       => 'meta_value',
  50.                 'order'         => $order,
  51.                 'paged'         => get_query_var('paged')
  52.             );
  53.         }
  54.     }
  55.  
  56.  
  57.     if($layout == 'layout3'){
  58.         if( ( $event_cat == '' ) || ( $event_cat == 'themeumall' ) ){
  59.                 $args = array(
  60.                             'post_type'     => 'event',
  61.                             'showposts'     => $count,
  62.                             'meta_key'      => 'themeum_start_datetime',
  63.                             'meta_value'    => date('Y-m-d h:i'),
  64.                             'meta_compare'  => '<',
  65.                             'orderby'       => 'meta_value',
  66.                             'order'         => $order
  67.                         );
  68.                    
  69.             }else{
  70.                 $args = array(
  71.                             'post_type' => 'event',
  72.                             'showposts' => $count,
  73.                             'tax_query' => array(
  74.                                                     array(
  75.                                                         'taxonomy' => 'event-category',
  76.                                                         'field'    => 'slug',
  77.                                                         'terms'    => $event_cat,
  78.                                                     ),
  79.                                                 ),
  80.                             'meta_key'      => 'themeum_start_datetime',
  81.                             'meta_value'    => date('Y-m-d h:i'),
  82.                             'meta_compare'  => '<',
  83.                             'orderby'       => 'meta_value',
  84.                             'order'         => $order
  85.                         );
  86.                
  87.             }
  88.     }
  89.  
  90.     $query = new WP_Query($args);
  91.  
  92.     if( $layout == 'layout1' ){
  93.  
  94.         $output .= '<div class="shortcode-upcoming-event">';
  95.         if ( $query->have_posts() ) :
  96.             while ( $query->have_posts() ) : $query->the_post();
  97.                 $event_start_datetime = get_post_meta(get_the_ID(),'themeum_start_datetime', true );
  98.                 $event_end_datetime = get_post_meta(get_the_ID(),'themeum_end_datetime', true );
  99.                 $themeum_venue = get_post_meta(get_the_ID(),'themeum_venue', true );
  100.                 $media_url ='';
  101.                 if( has_post_thumbnail( get_the_ID() ) ){
  102.                     $thumb_src =  wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'wpeducon-medium' );
  103.                     $media_url = $thumb_src[0];
  104.                 }
  105.                 $style = '';
  106.                 $style .= (!empty($media_url)) ? 'background-image: url('.$media_url.');' : '';
  107.  
  108.  
  109.                 $output .= '<div class="upcoming-event-content full-width-events clearfix">';
  110.                     $output .= '<div class="row">';
  111.                         $output .= '<div class="col-md-3 col-sm-3 col-xs-3" style="'.esc_html($style).'">';
  112.                             $output .= '<div class="entry-date-overlayer"></div>';
  113.                                 $output .= '<div class="entry-date">';
  114.                                     $output .= '<span class="entry-date-day">'.date_i18n( "d", strtotime($event_start_datetime)).'</span>';
  115.                                     $output .= '<span class="entry-date-month">'.date_i18n( "M,Y", strtotime($event_start_datetime)).'</span>';
  116.                                 $output .= '</div>';
  117.                             $output .= '</div>';
  118.                             $output .= '<div class="col-md-9 col-sm-9 col-xs-9">';
  119.                                 $output .= '<h3><a href="'.get_permalink().'">'.get_the_title().'</a></h3>';
  120.                                 $output .= '<span class="entry-date-time"><i class="fa fa-clock-o" aria-hidden="true"></i> '.date_i18n( "h:i A", strtotime($event_start_datetime)).' - '.date_i18n("h:i A", strtotime($event_end_datetime)) .'</span>';
  121.                             $output .= '<span class="entry-date-time"><i class="fa fa-map-signs" aria-hidden="true"></i> '.esc_html($themeum_venue).'</span>';
  122.                         $output .= '</div>';
  123.                     $output .= '</div>';
  124.                 $output .= '</div>';
  125.             endwhile;
  126.         endif;
  127.  
  128.         $output .= '</div>';
  129.     }
  130.  
  131.     if( $layout == 'layout2' ){
  132.         $output  = '<div class="event-countdown-wrapper-content ' . esc_attr($class) .'">';
  133.             $count = 1;
  134.             $x = 1;
  135.             if ( $query->have_posts() ) :
  136.                 while ( $query->have_posts() ) : $query->the_post();
  137.                     $datetime   = get_post_meta(get_the_ID(), 'themeum_start_datetime', true); ?>
  138.                     <script type="text/javascript">
  139.                         jQuery(function($) {
  140.                             $('#countdown-timer'+ <?php echo $count; ?> +'').countdown("<?php echo str_replace('-', '/', $datetime); ?>", function(event) {
  141.                                 $(this).html(event.strftime('<div class="event-countdown-section"><span class="countdown-date">%-D </span><span class="countdown-period">%!D: .<?php echo esc_html__("DAY", "string"); ?>,<?php echo esc_html__("DAYS", "string"); ?>;</span></div><div class="event-countdown-section"><span class="countdown-date">%-H </span><span class="countdown-period">%!H:<?php echo esc_html__("HOUR", "string"); ?>,<?php echo esc_html__("HOURS", "string"); ?>;</span></div><div class="event-countdown-section"><span class="countdown-date">%-M </span><span class="countdown-period">%!M:<?php echo esc_html__("MINUTE", "string"); ?>,<?php echo esc_html__("MINUTES", "string"); ?>;</span></div><div class="event-countdown-section"><span class="countdown-date">%-S </span><span class="countdown-period">%!S:<?php echo esc_html__("SECOND", "string"); ?>,<?php echo esc_html__("SECONDS", "string"); ?>;</span></div>'));
  142.                             });
  143.                         });
  144.                     </script>
  145.                     <?php
  146.                     if( $x == 1 ){ $output .= '<div class="row">'; }
  147.                     $output .= '<div class="col-xs-12 col-sm-6 col-md-4">';
  148.                         $output .= '<div class="single-event-content">';
  149.                             $output .= '<div class="event-single-img">';
  150.                             if (has_post_thumbnail( $post->ID ) ):
  151.                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'wpeducon-medium' );
  152.                                 $output .= '<img class="img-responsive" src="'.esc_url( $image[0] ).'" alt="'.get_the_title().'">';
  153.                             endif;
  154.                             $output .= '</div>'; #event-single-img
  155.                             $output .= '<div class="event-content-wrapper">';
  156.                                 $output .= '<h3 class="countdown-timer-title"><i class="fa fa-clock-o" aria-hidden="true"></i> '.date_i18n("F j, Y", strtotime($datetime)).'</h3>';
  157.                                 $output .= '<h3 class="countdown-timer-subtitle"><a href="'.get_permalink().'">'.get_the_title().'</a></h3>';
  158.                                 $output .= '<div id="countdown-timer'.$count.'" class="stringscountdown"></div>';
  159.                             $output .= '</div>'; #event-img
  160.                         $output .= '</div>'; # single-event-content
  161.                     $output .= '</div>'; # col-xs-12
  162.  
  163.                     if( $x == 3 ){
  164.                         $output .= '</div>'; # row
  165.                         $x = 1;
  166.                     }else{
  167.                         $x++;
  168.                     }
  169.                     $count++;
  170.                 endwhile;
  171.             endif;
  172.         $output .= '</div>'; // event-countdown-wrapper-content
  173.     }
  174.  
  175.  
  176.     if( $layout == 'layout3' ){
  177.         $output  = '<div class="event-countdown-wrapper-content ' . esc_attr($class) .'">';
  178.             $count = 1;
  179.             $x = 1;
  180.             if ( $query->have_posts() ) :
  181.                 while ( $query->have_posts() ) : $query->the_post();
  182.                     $datetime   = get_post_meta(get_the_ID(), 'themeum_start_datetime', true); ?>
  183.                    
  184.                     <?php
  185.                     if( $x == 1 ){ $output .= '<div class="row">'; }
  186.                     $output .= '<div class="col-xs-12 col-sm-6 col-md-4">';
  187.                         $output .= '<div class="single-event-content">';
  188.                             $output .= '<div class="event-single-img">';
  189.                             if (has_post_thumbnail( $post->ID ) ):
  190.                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'wpeducon-medium' );
  191.                                 $output .= '<img class="img-responsive" src="'.esc_url( $image[0] ).'" alt="'.get_the_title().'">';
  192.                             endif;
  193.                             $output .= '</div>'; #event-single-img
  194.                             $output .= '<div class="event-content-wrapper without-event">';
  195.                                 $output .= '<h3 class="countdown-timer-title"><i class="fa fa-clock-o" aria-hidden="true"></i> '.date_i18n("F j, Y", strtotime($datetime)).'</h3>';
  196.                                 $output .= '<h3 class="countdown-timer-subtitle"><a href="'.get_permalink().'">'.get_the_title().'</a></h3>';
  197.                                
  198.                             $output .= '</div>'; #event-img
  199.                         $output .= '</div>'; # single-event-content
  200.                     $output .= '</div>'; # col-xs-12
  201.  
  202.                     if( $x == 3 ){
  203.                         $output .= '</div>'; # row
  204.                         $x = 1;
  205.                     }else{
  206.                         $x++;
  207.                     }
  208.                     $count++;
  209.                 endwhile;
  210.             endif;
  211.         $output .= '</div>'; // event-countdown-wrapper-content
  212.     }
  213.  
  214.  
  215.     $page_numb   = max( 1, get_query_var('paged') );
  216.     $max_page    = $query->max_num_pages;
  217.  
  218.     ob_start();
  219.     wpeducon_pagination( $page_numb, $max_page );
  220.     $output .= ob_get_contents();
  221.     ob_clean();
  222.  
  223.     wp_reset_postdata();
  224.  
  225.  
  226.     return $output;
  227.  
  228. });
  229.  
  230.  
  231.  
  232. # Visual Composer
  233. if (class_exists('WPBakeryVisualComposerAbstract')) {
  234. vc_map(array(
  235.     "name"              => esc_html__("Educon Events", 'themeum-core'),
  236.     "base"              => "educon_events",
  237.     'icon'              => 'icon-thm-title',
  238.     "class"             => "",
  239.     "description"       => esc_html__("Widget Title Heading", 'themeum-core'),
  240.     "category"          => esc_html__('Educon', 'themeum-core'),
  241.     "params"            => array(
  242.  
  243.             array(
  244.                     "type"          => "dropdown",
  245.                     "heading"       => esc_html__("Title Heading", 'themeum-core'),
  246.                     "param_name"    => "layout",
  247.                     "value"         => array(
  248.                                             'Select'                =>'',
  249.                                             'Upcoming Event Style1' =>'layout1',
  250.                                             'Upcoming Event Style2' =>'layout2',
  251.                                             'Past Events'           =>'layout3'
  252.                                         ),
  253.             ), 
  254.            
  255.             array(
  256.                     "type"          => "dropdown",
  257.                     "heading"       => __("Select The Performer Category:","themeum-core"),
  258.                     "param_name"    => "event_cat",
  259.                     "value"         => themeum_cat_list( 'event-category' )
  260.             ),
  261.  
  262.             array(
  263.                 "type"          => "dropdown",
  264.                 "heading"       => esc_html__("Order", 'themeum-core'),
  265.                 "param_name"    => "order",
  266.                 "value"         => array('DESC'=>'DESC','ASC'=>'ASC'),
  267.             ),
  268.  
  269.             array(
  270.                 "type"              => "textfield",
  271.                 "heading"           => __("Title", "themeum-core"),
  272.                 "param_name"        => "title",
  273.                 "value"             => "",
  274.                 "admin_label"       =>true,
  275.             ),
  276.            
  277.  
  278.             array(
  279.                 "type"              => "textfield",
  280.                 "heading"           => __("Maximum Number of Event:", "themeum-core"),
  281.                 "param_name"        => "count",
  282.                 "value"             => "",
  283.             ),
  284.  
  285.             array(
  286.                 "type"              => "textfield",
  287.                 "heading"           => __("Extra CSS Class", "themeum-core"),
  288.                 "param_name"        => "class",
  289.                 "value"             => "",
  290.             ),
  291.  
  292.         )
  293.     ));
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement