Advertisement
rejuancse

video-post

Jan 25th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.93 KB | None | 0 0
  1. <?php
  2. add_shortcode( 'themeum_popular_post', function($atts, $content = null) {
  3.  
  4.     extract(shortcode_atts(array(
  5.         'category'                      => '',
  6.         'style'                         => 'style1',
  7.         'overlay'                       => 'yes',
  8.         'number'                        => '6',
  9.         'class'                         => '',        
  10.         'order'                         => 'DESC',  
  11.         'show_category'                 => 'yes',
  12.         'show_author'                   => 'yes',
  13.         'show_date'                     => 'yes',    
  14.         ), $atts));
  15.  
  16.     global $post;
  17.  
  18.     $output     = '';
  19.     $posts= 0;
  20.     if (isset($category) && $category!='') {
  21.         $idObj  = get_category_by_slug( $category );
  22.        
  23.             if (isset($idObj) && $idObj!='') {
  24.                 $idObj  = get_category_by_slug( $category );
  25.                 $cat_id = $idObj->term_id;
  26.  
  27.                 $args = array(
  28.                     'category'          => $cat_id,
  29.                     'meta_key'          => 'themeum_video',
  30.                     'orderby'           => 'meta_value_num',
  31.                     'order'             => $order,
  32.                     'posts_per_page'    => $number,
  33.                 );
  34.                 $posts = get_posts($args);
  35.             }else{
  36.                 echo "Please Enter a valid category name";
  37.                 $args = 0;
  38.             }
  39.         }else{
  40.             $args = array (
  41.                     'meta_key'          => 'themeum_video',
  42.                     'orderby'           => 'meta_value_num',
  43.                     'order'             => $order,
  44.                     'posts_per_page'    => $number,
  45.                 );
  46.             $posts = get_posts($args);
  47.         }
  48.  
  49.  
  50.             if(count($posts)>0){
  51.                 $output .= '<div class="highlights themeum-default-ul popular-items-wrap '.esc_attr($class).'">';
  52.                 $output .= '<div class="row">';
  53.                 $i=1;
  54.                 foreach ($posts as $post): setup_postdata($post);
  55.  
  56.                     $key_1_value = get_post_meta($post->ID, 'themeum_video', true );
  57.  
  58.                     $format = get_post_format( $post_id );
  59.  
  60.                     if ($format == 'video') {
  61.                         if($i==1){
  62.                             $output .= '<div class="highlights-item highlight-style3 popular-items-wrap col-md-6">';
  63.                             if ( has_post_thumbnail() ) {
  64.                                 $output .= '<div class="themeum-default-wrapper highlights-wrapper themeum-overlay-wrap '.esc_attr($overlay).'">';
  65.                                 $output .= '<a href="'.get_permalink().'">'.get_the_post_thumbnail($post->ID, 'heighlights', array('class' => 'img-responsive')).'</a>';
  66.                                
  67.                                 $output .= '<div class="themeum-default-intro highlights-intro themeum-overlay">'; 
  68.                                 $output .= '<div class="themeum-overlay-inner">';
  69.                                 if ( $show_category == 'yes'){
  70.                                     $output .= '<span class="entry-category">';
  71.                                     $output .= get_the_category_list(', ');
  72.                                     $output .= '</span>';
  73.                                 }
  74.                                 $output .= '<h3 class="entry-title"><a href="'.get_permalink().'">'. get_the_title() .'</a></h3>';
  75.                                 if ( $show_date == 'yes'){
  76.                                     $output .= '<span class="entry-date">';
  77.                                     $output .= get_the_date('d M Y');
  78.                                     $output .= '</span>';  
  79.                                 }      
  80.                                 $output .= '</div>';//themeum-overlay-inner
  81.                                 $output .= '</div>';//highlights-intro
  82.                                 $output .= '</div>';//highlights-wrapper   
  83.                             }else {
  84.                                 $output .= '<div class="themeum-default-wrapper highlights-wrapper">';
  85.                                 $output .= '<div class="highlights-intro themeum-overlay-inner no-image">';
  86.                                 if ( $show_category == 'yes'){
  87.                                     $output .= '<span class="entry-category">';
  88.                                     $output .= get_the_category_list(', ');
  89.                                     $output .= '</span>';
  90.                                 }
  91.                                 $output .= '<h3 class="entry-title"><a href="'.get_permalink().'">'. get_the_title() .'</a></h3>';
  92.                                 if ( $show_date == 'yes'){
  93.                                     $output .= '<span class="entry-date">';
  94.                                     $output .= get_the_date('d M Y');
  95.                                     $output .= '</span>';  
  96.                                 }      
  97.                                 $output .= '</div>';//themeum-overlay-inner                
  98.                                 $output .= '</div>';//highlights-wrapper
  99.                             }
  100.                             $output .= '</div>';    
  101.                            
  102.                         }else {
  103.  
  104.                             $output .= '<div class="popular-item all-items style3-wrap col-md-6">';
  105.                             $output .= '<div class="popular-news-wrapper popular-items-wrap clearfix">';
  106.                             if ( has_post_thumbnail() ) {
  107.                                 $output .= '<div class="popular-image">';
  108.                                 $output .= '<div class="themeum-overlay-wrap '.esc_attr($overlay).'">';
  109.                                 $output .= '<a href="'.get_permalink().'">'.get_the_post_thumbnail($post->ID, 'blog-thumb', array('class' => 'img-responsive')).'</a>';
  110.                                 $output .= '</div>';//themeum-overlay-wrap
  111.                                 $output .= '</div>';//image
  112.                                
  113.                                 $output .= '<div class="popular-news-intro">'; 
  114.                                 if ( $show_category == 'yes'){
  115.                                     $output .= '<span class="entry-category">';
  116.                                     $output .= get_the_category_list(', ');
  117.                                     $output .= '</span>';
  118.                                 }
  119.                                 $output .= '<h3 class="entry-title"><a href="'.get_permalink().'">'. get_the_title() .'</a></h3>';
  120.                                 if ( $show_date == 'yes'){
  121.                                     $output .= '<span class="entry-date">';
  122.                                     $output .= get_the_date('d M Y');
  123.                                     $output .= '</span>';  
  124.                                 }      
  125.                                 $output .= '</div>';//popular-intro
  126.                             }else {
  127.                                 $output .= '<div class="popular-news-intro">'; 
  128.                                 if ( $show_category == 'yes'){
  129.                                     $output .= '<span class="entry-category">';
  130.                                     $output .= get_the_category_list(', ');
  131.                                     $output .= '</span>';
  132.                                 }
  133.                                 $output .= '<h3 class="entry-title"><a href="'.get_permalink().'">'. get_the_title() .'</a></h3>';
  134.                                 if ( $show_date == 'yes'){
  135.                                     $output .= '<span class="entry-date">';
  136.                                     $output .= get_the_date('d M Y');
  137.                                     $output .= '</span>';  
  138.                                 }      
  139.                                 $output .= '</div>';//popular-intro
  140.                             }
  141.                             $output .= '</div>';//popular-wrapper
  142.                             $output .= '</div>';
  143.                         }
  144.                     }
  145.                 $i++;
  146.                 endforeach;
  147.  
  148.                 wp_reset_postdata();  
  149.                 $output .= '</div>';
  150.                 $output .= '</div>';
  151.                  
  152.             }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.        
  159.  
  160.     return $output;
  161.  
  162. });
  163.  
  164. function themeum_all_cat_list_2(){
  165.     $cat_lists = get_categories();
  166.     $all_cat_list = array('All Category'=>'');
  167.     foreach($cat_lists as $cat_list){
  168.         $all_cat_list[$cat_list->cat_name] = $cat_list->cat_name;
  169.     }
  170.     return $all_cat_list;
  171. }
  172.  
  173. //Visual Composer
  174. if (class_exists('WPBakeryVisualComposerAbstract')) {
  175.     vc_map(array(
  176.         "name" => __("Themeum Popular Post", "themeum"),
  177.         "base" => "themeum_popular_post",
  178.         'icon' => 'icon-thm-popular-post',
  179.         "class" => "",
  180.         "description" => __("Widget Title Heading", "themeum"),
  181.         "category" => __('Themeum', "themeum"),
  182.         "params" => array( 
  183.  
  184.             array(
  185.                 "type" => "dropdown",
  186.                 "heading" => __("Style", "themeum"),
  187.                 "param_name" => "style",
  188.                 "value" => array( 'Select'=>'','Style 1'=>'style1','Style 2'=>'style2', 'Style 3' => 'style3' ),
  189.             ), 
  190.  
  191.             array(
  192.                 "type" => "dropdown",
  193.                 "heading" => __("Image Overlay", "themeum"),
  194.                 "param_name" => "overlay",
  195.                 "value" => array('Select'=>'','YES'=>'yes','NO'=>'no'),
  196.             ),             
  197.  
  198.             array(
  199.                 "type" => "dropdown",
  200.                 "heading" => __("Category Filter", "themeum"),
  201.                 "param_name" => "category",
  202.                 "value" => themeum_all_cat_list_2(),
  203.                 ), 
  204.  
  205.             array(
  206.                 "type" => "textfield",
  207.                 "heading" => __("Number of items", "themeum"),
  208.                 "param_name" => "number",
  209.                 "value" => "",
  210.                 ),         
  211.                
  212.  
  213.             array(
  214.                 "type" => "dropdown",
  215.                 "heading" => __("Order", "themeum"),
  216.                 "param_name" => "order",
  217.                 "value" => array('Select'=>'','DESC'=>'DESC','ASC'=>'ASC'),
  218.                 ),             
  219.  
  220.             array(
  221.                 "type" => "dropdown",
  222.                 "heading" => __("Show Category", "themeum"),
  223.                 "param_name" => "show_category",
  224.                 "value" => array('Select'=>'','YES'=>'yes','NO'=>'no'),
  225.                 ),             
  226.  
  227.             array(
  228.                 "type" => "dropdown",
  229.                 "heading" => __("Show Author", "themeum"),
  230.                 "param_name" => "show_author",
  231.                 "value" => array('Select'=>'','YES'=>'yes','NO'=>'no'),
  232.                 ), 
  233.  
  234.             array(
  235.                 "type" => "dropdown",
  236.                 "heading" => __("Show Date", "themeum"),
  237.                 "param_name" => "show_date",
  238.                 "value" => array('Select'=>'','YES'=>'yes','NO'=>'no'),
  239.                 ),             
  240.  
  241.  
  242.             array(
  243.                 "type" => "textfield",
  244.                 "heading" => __("Custom Class", "themeum"),
  245.                 "param_name" => "class",
  246.                 "value" => "",
  247.                 ), 
  248.  
  249.             )
  250.  
  251.         ));
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement