Advertisement
rejuancse

thm-post-slider

Apr 1st, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.70 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Elementor;
  4.  
  5. if ( ! defined( 'ABSPATH' ) ) exit; # Exit if accessed directly
  6.  
  7. class Themeum_Widget_Post_Slider extends Widget_Base {
  8.  
  9.     public function get_name() {
  10.         return 'newskit-post-slider';
  11.     }
  12.  
  13.     public function get_title() {
  14.         return __( 'Themeum Post Slider', 'themeum-core' );
  15.     }
  16.  
  17.     public function get_icon() {
  18.         return 'eicon-gallery-grid';
  19.     }
  20.  
  21.     public function get_categories() {
  22.         return [ 'themeum-elementor' ];
  23.     }
  24.  
  25.  
  26.     protected function _register_controls() {
  27.  
  28.         $this->start_controls_section(
  29.             'woo_product',
  30.             [
  31.                 'label'     => __( 'Post Element', 'themeum-core' )
  32.             ]
  33.         );
  34.         $this->add_control(
  35.           'post_number',
  36.           [
  37.             'label'         => __( 'Number of Posts', 'themeum-core' ),
  38.             'type'          => Controls_Manager::NUMBER,
  39.             'label_block'   => true,
  40.             'default'       => __( '9', 'themeum-core' ),
  41.  
  42.           ]
  43.         );
  44.         $this->add_control(
  45.           'post_cat',
  46.           [
  47.              'label'    => __( 'Product Category', 'themeum-core' ),
  48.              'type'     => Controls_Manager::SELECT,
  49.              'options'  => themeum_cat_list( 'category' ),
  50.              'multiple' => true,
  51.              'default'  => 'allpost'
  52.           ]
  53.         );
  54.         $this->add_control(
  55.             'post_order_by',
  56.             [
  57.                 'label'     => __( 'Order', 'themeum-core' ),
  58.                 'type'      => Controls_Manager::SELECT,
  59.                 'default'   => 'DESC',
  60.                 'options'   => [
  61.                         'DESC'      => __( 'Descending', 'themeum-core' ),
  62.                         'ASC'       => __( 'Ascending', 'themeum-core' ),
  63.                     ],
  64.             ]
  65.         );
  66.         $this->add_control(
  67.           'textlimit',
  68.           [
  69.             'label'         => __( 'Text Limit Of Content', 'themeum-core' ),
  70.             'type'          => Controls_Manager::NUMBER,
  71.             'label_block'   => true,
  72.             'default'       => 280,
  73.           ]
  74.         );
  75.         $this->end_controls_section();
  76.  
  77.  
  78.         # Title Section
  79.         $this->start_controls_section(
  80.             'section_title_style',
  81.             [
  82.                 'label'     => __( 'Title', 'themeum-core' ),
  83.                 'tab'       => Controls_Manager::TAB_STYLE,
  84.             ]
  85.         );
  86.         $this->add_control(
  87.             'border_radius',
  88.             [
  89.                 'label'         => __( 'Border Radius', 'themeum-core' ),
  90.                 'type'          => Controls_Manager::DIMENSIONS,
  91.                 'size_units'    => [ 'px', '%' ],
  92.                 'selectors'     => [
  93.                     '{{WRAPPER}} .blog-post-item-col .newskit-index-post' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
  94.                 ],
  95.             ]
  96.         );
  97.         $this->add_control(
  98.             'title_color',
  99.             [
  100.                 'label'     => __( 'Title Color', 'themeum-core' ),
  101.                 'type'      => Controls_Manager::COLOR,
  102.                 'scheme'    => [
  103.                         'type' => Scheme_Color::get_type(),
  104.                         'value' => Scheme_Color::COLOR_1,
  105.                     ],
  106.                 'selectors' => [
  107.                     '{{WRAPPER}} .newskit-post .content-item-title a' => 'color: {{VALUE}};',
  108.                 ],
  109.             ]
  110.         );
  111.         $this->add_group_control(
  112.             Group_Control_Typography::get_type(),
  113.             [
  114.                 'name'      => 'typography',
  115.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  116.                 'selector'  => '{{WRAPPER}} .newskit-post .content-item-title a',
  117.             ]
  118.         );
  119.         $this->end_controls_section();
  120.         # Title Section End
  121.  
  122.         #Pagination Section
  123.         $this->start_controls_section(
  124.             'section_pagination_style',
  125.             [
  126.                 'label'     => __( 'Pagination', 'themeum-core' ),
  127.                 'tab'       => Controls_Manager::TAB_STYLE,
  128.             ]
  129.         );
  130.  
  131.         $this->add_responsive_control(
  132.             'post_align',
  133.             [
  134.                 'label'     => __( 'Alignment', 'themeum-core' ),
  135.                 'type'      => Controls_Manager::CHOOSE,
  136.                 'options'   => [
  137.                     'left'      => [
  138.                         'title' => __( 'Left', 'themeum-core' ),
  139.                         'icon'  => 'fa fa-align-left',
  140.                     ],
  141.                     'center'    => [
  142.                         'title' => __( 'Center', 'themeum-core' ),
  143.                         'icon'  => 'fa fa-align-center',
  144.                     ],
  145.                     'right'     => [
  146.                         'title' => __( 'Right', 'themeum-core' ),
  147.                         'icon'  => 'fa fa-align-right',
  148.                     ],
  149.                     'justify'   => [
  150.                         'title' => __( 'Justified', 'themeum-core' ),
  151.                         'icon'  => 'fa fa-align-justify',
  152.                     ],
  153.                 ],
  154.                 'default'   => 'center',
  155.                 'selectors' => [
  156.                     '{{WRAPPER}} .themeum-pagination' => 'text-align: {{VALUE}}; display: inline-block; width: 100%;',
  157.                 ],
  158.             ]
  159.         );
  160.         $this->end_controls_section();
  161.  
  162.         #Subtitle Section
  163.         $this->start_controls_section(
  164.             'section_price_style',
  165.             [
  166.                 'label'     => __( 'Subtitle', 'themeum-core' ),
  167.                 'tab'       => Controls_Manager::TAB_STYLE,
  168.             ]
  169.         );
  170.  
  171.         $this->add_control(
  172.             'content_color',
  173.             [
  174.                 'label'     => __( 'Content Color', 'themeum-core' ),
  175.                 'type'      => Controls_Manager::COLOR,
  176.                 'scheme'    => [
  177.                         'type' => Scheme_Color::get_type(),
  178.                         'value' => Scheme_Color::COLOR_2,
  179.                     ],
  180.                 'selectors' => [
  181.                     '{{WRAPPER}} .newskit-post .entry-summary' => 'color: {{VALUE}};',
  182.                 ],
  183.             ]
  184.         );
  185.  
  186.         $this->add_group_control(
  187.             Group_Control_Typography::get_type(),
  188.             [
  189.                 'name'      => 'typography2',
  190.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_2,
  191.                 'selector'  => '{{WRAPPER}} .newskit-post .entry-summary',
  192.             ]
  193.         );
  194.     } # function _register_controls end
  195.  
  196.     protected function render( ) {
  197.  
  198.         $settings           = $this->get_settings();
  199.         $post_number        = $settings['post_number'];
  200.         $post_cat           = $settings['post_cat'];
  201.         $post_order_by      = $settings['post_order_by'];
  202.         $textlimit          = $settings['textlimit'];
  203.         $page_numb          = max( 1, get_query_var('paged') );
  204.  
  205.         # Query Build
  206.         $arg = array(
  207.                 'post_type'   =>  'post',
  208.                 'post_status' => 'publish',
  209.             );
  210.         if( $post_order_by ){
  211.             $arg['order'] = $post_order_by;
  212.         }
  213.         if( $page_numb ){
  214.             $arg['paged'] = $page_numb;
  215.         }
  216.         if( $post_number ){
  217.             $arg['posts_per_page'] = $post_number;
  218.         }
  219.         if( $post_cat ){
  220.             if( $post_cat != 'allpost' ){
  221.                 $cat_data = array();
  222.                 $cat_data['relation'] = 'AND';
  223.                 $cat_data[] = array(
  224.                         'taxonomy'  => 'category',
  225.                         'field'     => 'slug',
  226.                         'terms'     => $post_cat
  227.                     );
  228.                 $arg['tax_query'] = $cat_data;
  229.             }
  230.         }
  231.  
  232.         $data = new \WP_Query( $arg );
  233.     ?>
  234.  
  235.  
  236.         <div class="container-fluid healine-wrapper slider-post-cont-wrap">
  237.  
  238.         <?php
  239.             $paged      = (get_query_var('paged')) ? get_query_var('paged') : 1;
  240.             $args       = array(
  241.                             'post_type' => 'post',
  242.                             'paged'     => $paged
  243.                         );
  244.             $index      = 1;
  245. ?>
  246.  
  247.             <div class="themeum-post-slider" >
  248.  
  249.             <?php
  250.                 if ( $data->have_posts() ) :
  251.                 while ( $data->have_posts() ) : $data->the_post();
  252.                 ?>
  253.                    
  254.                     <div class="thm-slider-wrap">
  255.                         <div class="section-img">
  256.                             <?php  if ( has_post_thumbnail()) { ?>
  257.                                 <a class="item-image"  href="<?php get_permalink(); ?>">
  258.                                     <?php echo get_the_post_thumbnail(get_the_ID(), 'newskit-slider', array('class' => 'img-responsive')); ?>      
  259.                                 </a>
  260.                             <?php } ?>
  261.  
  262.                             <!-- add js file: $('.prettySocial').prettySocial(); -->
  263.                             <!-- CSS file add:
  264.  
  265.                                 .thm-slider-wrap .section-img {
  266.                                     width: 50%;
  267.                                     float: left;
  268.                                     overflow: hidden;
  269.                                     position: relative;
  270.                                 }
  271.                                 .thm-slider-wrap:hover .post-share-social{
  272.                                      opacity: 1;
  273.                                      visibility: visible;
  274.                                 }
  275.                              -->
  276.  
  277.                             <div class="article-image-wrap">
  278.                                 <div class="post-share-social">
  279.                                     <span class="share-button"><i class="fa fa-share-square-o"></i></span>
  280.                                     <div class="post-share-social-others">
  281.                                         <a href="#" data-type="facebook" class="fa fa-facebook prettySocial"></a>
  282.                                         <a href="#" data-type="twitter" class="fa fa-twitter prettySocial"></a>
  283.                                         <a href="#" data-type="googleplus" class="fa fa-google-plus prettySocial"></a>
  284.                                     </div>
  285.                                 </div>
  286.                             </div>
  287.                            
  288.                         </div>
  289.                         <div class="total-content">
  290.                             <?php if ( get_theme_mod( 'blog_category', true ) ): ?>
  291.                             <ul class="blog-post-cat">
  292.                                 <?php if ( get_theme_mod( 'blog_category', true ) ): ?>
  293.                                     <li class="meta-category"><?php printf(esc_html__('%s', 'themeum-core'), get_the_category_list(' ')); ?></li>
  294.                                 <?php endif; ?>
  295.                             </ul>
  296.                             <?php endif; ?>
  297.  
  298.                             <div class="blog-date-wrapper">
  299.                                 <span><time datetime="<?php echo get_the_date('Y-m-d') ?>"><?php echo get_the_date(); ?></time></span>
  300.                             </div>
  301.                             <h2><a href="<?php echo get_the_permalink(); ?>"><?php the_title(); ?></a></h2>
  302.                             <?php
  303.                                 if ( $textlimit ) {
  304.                                     if (get_theme_mod( 'blog_intro_text_en', true )) {
  305.                                         echo newskit_excerpt_max_charlength($textlimit);
  306.                                     }
  307.                                 } else {
  308.                                     the_content();
  309.                                 }
  310.                             ?>
  311.                         </div>
  312.                     </div>
  313.                    
  314.                 <?php
  315.                 endwhile;
  316.                
  317.                 endif;?>
  318.             </div>
  319.         <?php  wp_reset_postdata();
  320.            
  321.         ?>
  322.     </div><!-- row (inner) -->
  323.  
  324.  
  325.     <?php }
  326.     protected function _content_template() { }
  327. }
  328.  
  329. Plugin::instance()->widgets_manager->register_widget_type( new Themeum_Widget_Post_Slider() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement