Advertisement
rejuancse

slider

Jan 25th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.41 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *  Themeum Post Slider
  5. */
  6.  
  7. add_shortcode( 'themeum_post_slider', function( $atts, $content = null ) {
  8.  
  9.     extract(shortcode_atts(array(
  10.         'category'                      => '',
  11.         'number'                        => '4',
  12.         'class'                         => '',
  13.         'order_by'                      => 'date',          
  14.         'order'                         => 'DESC',  
  15.         'time'                          => '',
  16.         'disable_slider'                => '',
  17.         'slidenav'          => 'true',
  18.         'autoplay'          => 'true',
  19.         'slidecolumn'       => '4',
  20.     ), $atts));
  21.  
  22.     global $post;
  23.  
  24.     $posts= 0;
  25.  
  26.     if (isset($category) && $category!='') {
  27.         $idObj  = get_category_by_slug( $category );
  28.        
  29.         if (isset($idObj) && $idObj!='') {
  30.             $idObj  = get_category_by_slug( $category );
  31.             $cat_id = $idObj->term_id;
  32.  
  33.             $args = array(
  34.                 'category'          => $cat_id,
  35.                 'orderby'           => $order_by,
  36.                 'order'             => $order,
  37.                 'posts_per_page'    => $number,
  38.             );
  39.             $posts = get_posts($args);
  40.         }
  41.     }else{
  42.         $args = array(
  43.             'orderby'           => $order_by,
  44.             'order'             => $order,
  45.             'posts_per_page'    => $number,
  46.         );
  47.         $posts = get_posts($args);
  48.     }
  49.  
  50.     $output = '';
  51.  
  52.     if($disable_slider == 'enable'){
  53.         $time = 'false';
  54.     }
  55.  
  56.     // $output  .= '<div class="row">';
  57.     $output  .= '<div data-number="'.esc_attr($slidecolumn).'" data-aplay="'.esc_attr($rautoplay).'" data-testnav="'.esc_attr($rslidenav).'" class="slider-style1 owl-carousel owl-theme">';
  58.     $j=0;
  59.  
  60.     foreach ($posts as $post){
  61.         setup_postdata( $post );
  62.              if ( has_post_thumbnail() ) {
  63.  
  64.                 $image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
  65.  
  66.                 if( $j == 0 ){
  67.                     $output .= '<div class="item active" style="min-height:570px; background-image: url('.esc_url($image_url[0]).');background-repeat:no-repeat;background-position:center;background-size:cover;">';
  68.                 }else{
  69.                     $output .= '<div class="item" style="min-height:570px; background-image: url('.esc_url($image_url[0]).');background-repeat:no-repeat;background-size:cover;background-position:center;">';
  70.                 }
  71.                 $output .= '<div class="container">';
  72.                     $output .= '<div class="row">';
  73.                         $output .= '<div class="post-slider-wrap col-md-6 col-sm-6 col-xs-12">';
  74.                             $output .= '<div class="post-slider-in clearfix">';
  75.                                 $output .= '<div class="post-slider-innner">';
  76.                                 $output .= '<span class="entry-category">';
  77.                                 $output .= get_the_category_list(', ');
  78.                                 $output .= '</span>';
  79.                                 $output .= '<h2 class="slider-title"><a href="'.get_permalink().'">'.get_the_title().'</a></h2>';
  80.                                 $output .= '<p class="slider-excerpt">'.calcio_excerpt_max_charlength(100).'</p>';
  81.                                 $output .= '</div>'; //handpick-slider-innner
  82.                             $output .= '</div>'; //handpick-slider-in
  83.                         $output .= '</div>'; //col-sm-7
  84.                     $output .= '</div>'; //row
  85.                 $output .= '</div>'; //container
  86.             $output .= '</div>'; //item
  87.            
  88.             $j++;
  89.         }
  90.     }
  91.     wp_reset_postdata();    
  92.     $output .= '</div>';
  93.     // $output .= '</div>';
  94.  
  95.     # JS time
  96.    $output .= "<script type='text/javascript'>jQuery(document).ready(function() { jQuery('.nano').nanoScroller(); jQuery('#themeum-post-slider').carousel({ interval: ".$time." }) });</script>";
  97.  
  98.     return $output;
  99.  
  100. });
  101.  
  102.  
  103. function themeum_post_cat_list(){
  104.     $cat_lists = get_categories();
  105.     $all_cat_list = array('All Category'=>'');
  106.     foreach($cat_lists as $cat_list){
  107.         $all_cat_list[$cat_list->cat_name] = $cat_list->cat_name;
  108.     }
  109.     return $all_cat_list;
  110. }
  111.  
  112. # Visual Composer
  113. if (class_exists('WPBakeryVisualComposerAbstract')) {
  114.     vc_map(array(
  115.         "name"          => esc_html__("Themeum Post Slider", 'themeum-core'),
  116.         "base"          => "themeum_post_slider",
  117.         'icon'          => 'icon-thm-slide',
  118.         "class"         => "",
  119.         "description"   => esc_html__("Widget Title Heading", 'themeum-core'),
  120.         "category"      => __('Calcio', "themeum-core"),
  121.         "params"        => array(              
  122.  
  123.             array(
  124.                 "type"          => "dropdown",
  125.                 "heading"       => esc_html__("Category Name", 'themeum-core'),
  126.                 "param_name"    => "category",
  127.                 "value"         => themeum_post_cat_list(),
  128.             ),                      
  129.             array(
  130.                 "type"          => "textfield",
  131.                 "heading"       => esc_html__("Number of items", 'themeum-core'),
  132.                 "param_name"    => "number",
  133.                 "value"         => "",
  134.             ),          
  135.             array(
  136.                 "type"          => "dropdown",
  137.                 "heading"       => esc_html__("OderBy", 'themeum-core'),
  138.                 "param_name"    => "order_by",
  139.                 "value"         => array('Date'=>'date','Title'=>'title','Modified'=>'modified','Author'=>'author','Random'=>'rand'),
  140.             ),              
  141.             array(
  142.                 "type"          => "dropdown",
  143.                 "heading"       => esc_html__("Order", 'themeum-core'),
  144.                 "param_name"    => "order",
  145.                 "value"         => array('DESC'=>'DESC','ASC'=>'ASC'),
  146.             ),                          
  147.             array(
  148.                 "type"          => "textfield",
  149.                 "heading"       => esc_html__("Custom Class", 'themeum-core'),
  150.                 "param_name"    => "class",
  151.                 "value"         => "",
  152.             ),  
  153.             array(
  154.                 "type"          => "checkbox",
  155.                 "class"         => "",
  156.                 "heading"       => esc_html__("Disable Slider: ","themeum-core"),
  157.                 "param_name"    => "disable_slider",
  158.                 "value"         => array ( esc_html__('Disable','themeum-core') => 'enable'),
  159.                 "description"   => esc_html__("If you want disable slide check this.","themeum-core"),
  160.                 "group"         => "Slide"
  161.             ),
  162.  
  163.             array(
  164.                 "type"              => "dropdown",
  165.                 "class"             => "",
  166.                 "heading"           => esc_html__("Select Column Number",'themeum-core'),
  167.                 "param_name"        => "slidecolumn",
  168.                 "value"             => array(
  169.                     esc_html__("Select",'themeum-core')     =>'',
  170.                     esc_html__("Column 1",'themeum-core')   => '1',
  171.                     esc_html__("Column 2",'themeum-core')   => '2',
  172.                     esc_html__("Column 3",'themeum-core')   => '3',
  173.                     esc_html__("Column 4",'themeum-core')   => '4',
  174.                     esc_html__("Column 5",'themeum-core')   => '5',
  175.                 ),
  176.             ),
  177.             array(
  178.                 "type"              => "dropdown",
  179.                 "class"             => "",
  180.                 "heading"           => __("Auto Play",'themeum-core'),
  181.                 "param_name"        => "autoplay",
  182.                 "value"             => array('None'=>'','True'=>'true','False'=>'false'),
  183.             ),
  184.             array(
  185.                 "type"              => "dropdown",
  186.                 "class"             => "",
  187.                 "heading"           => __("Show Navigation",'themeum-core'),
  188.                 "param_name"        => "slidenav",
  189.                 "value"             => array('None'=>'','True'=>'true','False'=>'false'),
  190.             ),
  191.  
  192.  
  193.  
  194.             array(
  195.                 "type"          => "textfield",
  196.                 "heading"       => esc_html__("Sliding Time(Milliseconds Ex: 4000)", "themeum-core"),
  197.                 "param_name"    => "time",
  198.                 "value"         => "3000",
  199.                 "group"         => "Slide"
  200.             ),
  201.  
  202.         )
  203.  
  204.     ));
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement