Advertisement
rejuancse

thm-service-widgets.php

Dec 10th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.66 KB | None | 0 0
  1. <?php
  2. namespace Elementor;
  3.  
  4. if ( ! defined( 'ABSPATH' ) ) exit; # Exit if accessed directly
  5.  
  6. class Widget_Themeum_Service extends Widget_Base {
  7.     public function get_name() {
  8.         return 'thm-service';
  9.     }
  10.  
  11.     public function get_title() {
  12.         return __( 'Service', 'structure' );
  13.     }
  14.  
  15.     public function get_icon() {
  16.         return 'eicon-inner-section wts-eae-pe';
  17.     }
  18.  
  19.     public function get_categories() {
  20.         return [ 'themeum-elementor' ];
  21.     }
  22.  
  23.     protected function _register_controls() {
  24.        
  25.         $this->start_controls_section(
  26.             'section_title',
  27.             [
  28.                 'label'     => __( 'Service Settings', 'structure' ),
  29.             ]
  30.         );
  31.  
  32.         $this->add_control(
  33.           'service_category',
  34.             [
  35.              'label'        => __( 'Select Service', 'structure' ),
  36.              'type'         => Controls_Manager::SELECT,
  37.              'options'      => themeum_cat_list('portfolio-cat'),
  38.              'multiple'     => true,
  39.              'default'      => 'All'
  40.             ]
  41.         );
  42.  
  43.         $this->add_control(
  44.             'service_layout',
  45.             [
  46.                 'label'     => __( 'Order', 'structure' ),
  47.                 'type'      => Controls_Manager::SELECT,
  48.                 'default'   => 'layout_1',
  49.                 'options'   => [
  50.                         'layout_1'      => __( 'Layout 1', 'structure' ),
  51.                         'layout_2'      => __( 'Layout 2', 'structure' ),
  52.                     ],
  53.             ]
  54.         );
  55.         $this->add_control(
  56.             'service_number',
  57.             [
  58.             'label'         => __( 'Number of Service', 'structure' ),
  59.             'type'          => Controls_Manager::NUMBER,
  60.             'label_block'   => true,
  61.             'default'       => __( '6', 'structure' ),
  62.             ]
  63.         );
  64.         $this->add_control(
  65.             'service_column',
  66.             [
  67.                 'label'     => __( 'Number of Column', 'structure' ),
  68.                 'type'      => Controls_Manager::SELECT,
  69.                 'default'   => 4,
  70.                 'options'   => [
  71.                         '6'     => __( 'Two Column', 'structure' ),
  72.                         '4'     => __( 'Three Column', 'structure' ),
  73.                         '3'     => __( 'Four Column', 'structure' ),
  74.                     ],
  75.             ]
  76.         );
  77.         $this->add_control(
  78.             'service_order_by',
  79.             [
  80.                 'label'     => __( 'Order', 'structure' ),
  81.                 'type'      => Controls_Manager::SELECT,
  82.                 'default'   => 'DESC',
  83.                 'options'   => [
  84.                         'DESC'      => __( 'Descending', 'structure' ),
  85.                         'ASC'       => __( 'Ascending', 'structure' ),
  86.                     ],
  87.             ]
  88.         );
  89.         $this->add_control(
  90.             'service_show_title',
  91.             [
  92.                 'label'         => __( 'Show Title', 'structure' ),
  93.                 'type'          => Controls_Manager::SWITCHER,
  94.                 'default'       => 'yes',
  95.                 'label_on'      => __( 'Yes', 'structure' ),
  96.                 'label_off'     => __( 'No', 'structure' ),
  97.             ]
  98.         );
  99.         $this->add_control(
  100.             'service_show_category',
  101.             [
  102.                 'label'         => __( 'Show Category', 'structure' ),
  103.                 'type'          => Controls_Manager::SWITCHER,
  104.                 'default'       => 'yes',
  105.                 'label_on'      => __( 'Yes', 'structure' ),
  106.                 'label_off'     => __( 'No', 'structure' ),
  107.             ]
  108.         );
  109.         $this->add_control(
  110.             'main_title_color',
  111.             [
  112.                 'label'     => __( 'Sub Title Hover Color', 'structure' ),
  113.                 'type'      => Controls_Manager::COLOR,
  114.                 'scheme'    => [
  115.                     'type'  => Scheme_Color::get_type(),
  116.                     'value' => Scheme_Color::COLOR_1,
  117.                 ],
  118.                 'selectors' => [
  119.                     '{{WRAPPER}} .service-item-content-in .service-title a' => 'color: {{VALUE}};',
  120.                 ],
  121.                 'default'   => '#293340',
  122.                 'condition' => [
  123.                     'service_layout' => ['layout_1','layout_2']
  124.                 ],
  125.             ]
  126.         );
  127.         $this->add_control(
  128.             'main_sub_title_color',
  129.             [
  130.                 'label'     => __( 'Sub Title Hover Color', 'structure' ),
  131.                 'type'      => Controls_Manager::COLOR,
  132.                 'scheme'    => [
  133.                     'type'  => Scheme_Color::get_type(),
  134.                     'value' => Scheme_Color::COLOR_1,
  135.                 ],
  136.                 'selectors' => [
  137.                     '{{WRAPPER}} .service-item-content-in .service-category' => 'color: {{VALUE}};',
  138.                 ],
  139.                 'default'   => '#6D7784',
  140.                 'condition' => [
  141.                     'service_layout' => ['layout_1','layout_2']
  142.                 ],
  143.             ]
  144.         );
  145.         $this->end_controls_section();
  146.  
  147.         $this->start_controls_section(
  148.             'section_title_style',
  149.             [
  150.                 'label'     => __( 'Service', 'structure' ),
  151.                 'tab'       => Controls_Manager::TAB_STYLE,
  152.             ]
  153.         );
  154.         $this->add_control(
  155.             'spacing',
  156.             [
  157.                 'label'     => __( 'Width', 'structure' ),
  158.                 'type'      => Controls_Manager::SLIDER,
  159.                 'default'   => [
  160.                         'size'  => 1,
  161.                     ],
  162.                 'range'     => [
  163.                             'px' => [
  164.                                     'min'   => 0,
  165.                                     'max'   => 100,
  166.                                     'step'  => 1,
  167.                             ],
  168.                             '%' => [
  169.                                 'min' => 0,
  170.                                 'max' => 100,
  171.                             ],
  172.                 ],
  173.                 'size_units'    => [ 'px', '%' ],
  174.                 'selectors'     => [
  175.                     '{{WRAPPER}} .service-items' => 'padding: {{SIZE}}{{UNIT}};',
  176.                 ],
  177.             ]
  178.         );
  179.         $this->add_control(
  180.             'sub_text_bg',
  181.             [
  182.                 'label'     => __( 'Sub Text Background Color', 'structure' ),
  183.                 'type'      => Controls_Manager::COLOR,
  184.                 'scheme'    => [
  185.                     'type'  => Scheme_Color::get_type(),
  186.                     'value' => Scheme_Color::COLOR_1,
  187.                 ],
  188.                 'selectors' => [
  189.                     '{{WRAPPER}} .service-item-content' => 'background-color: {{VALUE}};',
  190.                 ],
  191.                 'default'   => '',
  192.             ]
  193.         );
  194.         $this->add_responsive_control(
  195.             'filter_align',
  196.             [
  197.                 'label'     => __( 'Filter Alignment', 'structure' ),
  198.                 'type'      => Controls_Manager::CHOOSE,
  199.                 'options'   => [
  200.                     'left'      => [
  201.                         'title' => __( 'Left', 'structure' ),
  202.                         'icon'  => 'fa fa-align-left',
  203.                     ],
  204.                     'center'    => [
  205.                         'title' => __( 'Center', 'structure' ),
  206.                         'icon'  => 'fa fa-align-center',
  207.                     ],
  208.                     'right'     => [
  209.                         'title' => __( 'Right', 'structure' ),
  210.                         'icon'  => 'fa fa-align-right',
  211.                     ],
  212.                     'justify'   => [
  213.                         'title' => __( 'Justified', 'structure' ),
  214.                         'icon'  => 'fa fa-align-justify',
  215.                     ],
  216.                 ],
  217.                 'default'   => '',
  218.                 'selectors' => [
  219.                     '{{WRAPPER}} .serviceFilter' => 'text-align: {{VALUE}};',
  220.                 ],
  221.             ]
  222.         );
  223.         $this->add_responsive_control(
  224.             'align',
  225.             [
  226.                 'label'     => __( 'Content Alignment', 'structure' ),
  227.                 'type'      => Controls_Manager::CHOOSE,
  228.                 'options'   => [
  229.                     'left'      => [
  230.                         'title' => __( 'Left', 'structure' ),
  231.                         'icon'  => 'fa fa-align-left',
  232.                     ],
  233.                     'center'    => [
  234.                         'title' => __( 'Center', 'structure' ),
  235.                         'icon'  => 'fa fa-align-center',
  236.                     ],
  237.                     'right'     => [
  238.                         'title' => __( 'Right', 'structure' ),
  239.                         'icon'  => 'fa fa-align-right',
  240.                     ],
  241.                     'justify'   => [
  242.                         'title' => __( 'Justified', 'structure' ),
  243.                         'icon'  => 'fa fa-align-justify',
  244.                     ],
  245.                 ],
  246.                 'default'   => '',
  247.                 'selectors' => [
  248.                     '{{WRAPPER}} .service-item-content' => 'text-align: {{VALUE}};',
  249.                 ],
  250.             ]
  251.         );
  252.         $this->add_control(
  253.             'title_color',
  254.             [
  255.                 'label'     => __( 'Title Color', 'structure' ),
  256.                 'type'      => Controls_Manager::COLOR,
  257.                 'scheme'    => [
  258.                     'type'  => Scheme_Color::get_type(),
  259.                     'value' => Scheme_Color::COLOR_1,
  260.                 ],
  261.                 'selectors' => [
  262.                     '{{WRAPPER}} .service-title a,{{WRAPPER}} .overlay-cont2' => 'color: {{VALUE}};',
  263.                 ],
  264.                 'default'   => '#293340',
  265.             ]
  266.         );
  267.         $this->add_control(
  268.             'title_hover_color',
  269.             [
  270.                 'label'     => __( 'Title Hover Color', 'structure' ),
  271.                 'type'      => Controls_Manager::COLOR,
  272.                 'scheme'    => [
  273.                     'type'  => Scheme_Color::get_type(),
  274.                     'value' => Scheme_Color::COLOR_1,
  275.                 ],
  276.                 'selectors' => [
  277.                     '{{WRAPPER}} .service-title a:hover,{{WRAPPER}} .overlay-cont2:hover' => 'color: {{VALUE}};',
  278.                 ],
  279.                 'default'   => '#293340',
  280.             ]
  281.         );
  282.         $this->add_control(
  283.             'sub_title_color',
  284.             [
  285.                 'label'     => __( 'Sub Title Color', 'structure' ),
  286.                 'type'      => Controls_Manager::COLOR,
  287.                 'scheme'    => [
  288.                     'type'  => Scheme_Color::get_type(),
  289.                     'value' => Scheme_Color::COLOR_1,
  290.                 ],
  291.                 'selectors' => [
  292.                     '{{WRAPPER}} .service-category' => 'color: {{VALUE}};',
  293.                 ],
  294.                 'default'   => '#6D7784',
  295.             ]
  296.         );
  297.         $this->add_control(
  298.             'sub_title_hover_color',
  299.             [
  300.                 'label'     => __( 'Sub Title Hover Color', 'structure' ),
  301.                 'type'      => Controls_Manager::COLOR,
  302.                 'scheme'    => [
  303.                     'type'  => Scheme_Color::get_type(),
  304.                     'value' => Scheme_Color::COLOR_1,
  305.                 ],
  306.                 'selectors' => [
  307.                     '{{WRAPPER}} .service-category:hover' => 'color: {{VALUE}};',
  308.                 ],
  309.                 'default'   => '#6D7784',
  310.             ]
  311.         );
  312.         $this->add_control(
  313.             'title_bg_color',
  314.             [
  315.                 'label'     => __( 'Background Color', 'structure' ),
  316.                 'type'      => Controls_Manager::COLOR,
  317.                 'scheme'    => [
  318.                     'type'  => Scheme_Color::get_type(),
  319.                     'value' => Scheme_Color::COLOR_1,
  320.                 ],
  321.                 'default'   => '#ffffff',
  322.             ]
  323.         );
  324.         $this->add_control(
  325.             'title_bg_color_stop',
  326.             [
  327.                 'label'     => __( 'Background Color Stop', 'structure' ),
  328.                 'type'      => Controls_Manager::COLOR,
  329.                 'scheme'    => [
  330.                     'type'  => Scheme_Color::get_type(),
  331.                     'value' => Scheme_Color::COLOR_1,
  332.                 ],
  333.                 'selectors' => [
  334.                     '{{WRAPPER}} .layout_3 .service-item-content-in,{{WRAPPER}} .overlay-cont2,{{WRAPPER}} .service-items:hover .caption-full-width,{{WRAPPER}} .service-items:hover .service-layout2' => '    background-image: linear-gradient(190deg, {{title_bg_color.VALUE}} 0%, {{title_bg_color_stop.VALUE}} 100%);;',
  335.                 ],
  336.                 'default'   => '#ffffff',
  337.             ]
  338.         );
  339.         $this->add_group_control(
  340.             Group_Control_Typography::get_type(),
  341.             [
  342.                 'name'      => 'typography',
  343.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  344.                 'selector'  => '{{WRAPPER}} .service-title',
  345.             ]
  346.         );
  347.         $this->add_group_control(
  348.             Group_Control_Typography::get_type(),
  349.             [
  350.                 'name'      => 'typography_2',
  351.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  352.                 'selector'  => '{{WRAPPER}} .service-category',
  353.             ]
  354.         );
  355.         $this->end_controls_section();
  356.  
  357.     }
  358.  
  359.     protected function render( ) {
  360.         $settings   = $this->get_settings();
  361.         $service_cat = $settings['service_category'];
  362.        
  363.         if ($service_cat == 'All') {
  364.             $args = array(
  365.                 'post_type'         => 'portfolio',
  366.                 'posts_per_page'    => $settings['service_number'],
  367.                 'order'             => $settings['service_order_by'],            
  368.             );
  369.         }else{
  370.             $args = array(
  371.                 'post_type'         => 'portfolio',
  372.                 'posts_per_page'    => $settings['service_number'],
  373.                 'order'             => $settings['service_order_by'],
  374.                 'tax_query'         => array(
  375.                                             array(
  376.                                                 'taxonomy' => 'portfolio-cat',
  377.                                                 'field'    => 'slug',
  378.                                                 'terms'    => esc_attr($service_cat),
  379.                                                 ),
  380.                                             ),
  381.                              
  382.             );
  383.         }
  384.  
  385.         $data = new \WP_Query( $args );
  386.         global $post;
  387.         ?>
  388.  
  389.         <div class="filterable-service <?php echo $settings['service_layout']; ?>">
  390.             <div class="container">
  391.                 <div class="row">
  392.                    
  393.                     <?php
  394.                         if ( $data->have_posts() ) :
  395.                         while ( $data->have_posts() ) : $data->the_post();
  396.  
  397.                         $external_link  = esc_attr(get_post_meta( get_the_ID(),'external_link',true));
  398.                        
  399.                         # category list
  400.                         $terms = get_the_terms(  get_the_ID(), 'portfolio-cat' );
  401.                         $term_name = '';
  402.                         if (is_array( $terms )){
  403.                             foreach ( $terms as $term )
  404.                             {
  405.                                 $term_name .= $term->slug.', ';
  406.                             }
  407.                         }
  408.                         $term_name = substr($term_name, 0, -2);
  409.                     ?>
  410.  
  411.            
  412.                         <div class="service-items col-<?php echo $settings['service_column'];?> <?php echo $term_name; ?>">
  413.                             <div class="service-single-items">
  414.  
  415.                                 <div class="service-thumb">
  416.                                     <?php if(has_post_thumbnail( get_the_ID())) {
  417.                                         $thumb  = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID()), 'structure-portfo'); ?>
  418.                                         <img class="img-responsive" src="<?php echo esc_url($thumb[0]); ?>"  alt="">
  419.                                     <?php } else { ?>
  420.                                         <img class="img-responsive" src="<?php echo get_template_directory_uri(); ?>'/images/recipes.jpg" alt="<?php _e('image','structure'); ?>">
  421.                                     <?php } ?>
  422.                                     <?php if( $settings['service_layout'] == 'layout_1' ){ ?>
  423.                                         <div class="caption-full-width">
  424.                                             <div class="overlay-cont">
  425.                                                 <?php if ( $settings['service_show_title'] == 'yes' ) { ?>
  426.                                                     <a class="overlay-btn" href="<?php the_permalink(  get_the_ID() ); ?>"><?php _e( 'View Case Study','structure'); ?></a>
  427.                                                 <?php } ?>
  428.                                             </div>
  429.                                         </div>
  430.                                     <?php } ?>
  431.                                 </div>
  432.  
  433.                                 <!-- Style 1 -->
  434.                                 <?php if( $settings['service_layout'] == 'layout_1' ){ ?>
  435.                                     <div class="service-item-content">
  436.                                         <div class="service-item-content-in">
  437.                                             <div>
  438.                                                 <?php if ( $settings['service_show_title'] == 'yes' ) { ?>
  439.                                                     <h3 class="service-title"><a href="<?php the_permalink(  get_the_ID() ); ?>"><?php echo get_the_title( get_the_ID()) ?></a></h3>
  440.                                                 <?php } ?>
  441.                                                 <?php if ( $settings['service_show_category'] == 'yes' ) {
  442.                                                     if($term_name != '') { ?>
  443.                                                         <span class="service-category"><?php echo $term_name; ?></span>
  444.                                                     <?php }
  445.                                                 } ?>
  446.                                             </div>
  447.                                         </div>
  448.                                     </div>
  449.                                 <?php } ?>
  450.  
  451.                                 <!-- Style 2 -->
  452.                                 <?php if( $settings['service_layout'] == 'layout_2' ){ ?>
  453.                                     <div class="service-layout2">
  454.                                         <?php if(has_post_thumbnail( get_the_ID() )) {
  455.                                             $photo = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ),'full' ); ?>
  456.                                             <a class="plus-icon cloud-zooms" href="<?php echo esc_url($photo[0]); ?>"><i class="fa fa-eye"></i></a>  
  457.                                         <?php } ?>
  458.                                         <div class="overlay-cont2">    
  459.                                             <a href="<?php echo get_permalink(); ?>" class="plus-icon"><i class="sl-eye"></i></a>
  460.                                             <?php if ( $settings['service_show_title'] == 'yes' ) { ?>
  461.                                                 <h3 class="service-title"><a href="<?php the_permalink(  get_the_ID() ); ?>"><?php echo get_the_title( get_the_ID()) ?></a></h3>
  462.                                             <?php } ?>
  463.                                             <?php if ( $settings['service_show_category'] == 'yes' ) {
  464.                                                 if($term_name != '') { ?>
  465.                                                     <span class="service-category"><?php echo $term_name; ?></span>
  466.                                                 <?php }
  467.                                             } ?>   
  468.                                         </div>
  469.                                     </div>
  470.                                 <?php } ?>
  471.  
  472.                             </div>
  473.                         </div>
  474.                     <?php endwhile; ?>
  475.                        
  476.                 </div>
  477.             </div>
  478.         </div>
  479.  
  480. <?php wp_reset_postdata(); endif; ?>
  481. <?php }
  482.  
  483. }
  484.  
  485. Plugin::instance()->widgets_manager->register_widget_type( new Widget_Themeum_Service() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement