Advertisement
rejuancse

newskit-featured-posts-newskit

Mar 26th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.53 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_Posts_Featured_Content extends Widget_Base {
  8.  
  9.     public function get_name() {
  10.         return 'newskit-featured-posts-newskit';
  11.     }
  12.  
  13.     public function get_title() {
  14.         return __( 'Themeum Total Featured Posts', '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_column',
  46.             [
  47.                 'label'     => __( 'Number of Column', 'themeum-core' ),
  48.                 'type'      => Controls_Manager::SELECT,
  49.                 'default'   => 4,
  50.                 'options'   => [
  51.                         '12'    => __( 'One Column', 'themeum-core' ),
  52.                         '6'     => __( 'Two Column', 'themeum-core' ),
  53.                         '4'     => __( 'Three Column', 'themeum-core' ),
  54.                         '3'     => __( 'Four Column', 'themeum-core' ),
  55.                     ],
  56.             ]
  57.         );
  58.         $this->add_control(
  59.           'post_cat',
  60.           [
  61.              'label'    => __( 'Product Category', 'themeum-core' ),
  62.              'type'     => Controls_Manager::SELECT,
  63.              'options'  => newskit_all_category_list( 'category' ),
  64.              'multiple' => true,
  65.              'default'  => 'allpost'
  66.           ]
  67.         );
  68.         $this->add_control(
  69.             'post_order_by',
  70.             [
  71.                 'label'     => __( 'Order', 'themeum-core' ),
  72.                 'type'      => Controls_Manager::SELECT,
  73.                 'default'   => 'DESC',
  74.                 'options'   => [
  75.                         'DESC'      => __( 'Descending', 'themeum-core' ),
  76.                         'ASC'       => __( 'Ascending', 'themeum-core' ),
  77.                     ],
  78.             ]
  79.         );
  80.         $this->add_control(
  81.           'textlimit',
  82.           [
  83.             'label'         => __( 'Text Limit Of Content', 'themeum-core' ),
  84.             'type'          => Controls_Manager::NUMBER,
  85.             'label_block'   => true,
  86.             'default'       => 280,
  87.           ]
  88.         );
  89.         $this->add_control(
  90.             'post_pagination',
  91.             [
  92.                 'label'         => __( 'Post Pagination', 'themeum-core' ),
  93.                 'type'          => Controls_Manager::SWITCHER,
  94.                 'default'       => 'No',
  95.                 'label_on'      => __( 'Yes', 'themeum-core' ),
  96.                 'label_off'     => __( 'No', 'themeum-core' ),
  97.                 'selectors'     => [
  98.                     '{{WRAPPER}} iframe' => 'pointer-events: none;',
  99.                 ],
  100.             ]
  101.         );
  102.  
  103.         $this->end_controls_section();
  104.  
  105.  
  106.         # Title Section
  107.         $this->start_controls_section(
  108.             'section_title_style',
  109.             [
  110.                 'label'     => __( 'Title', 'themeum-core' ),
  111.                 'tab'       => Controls_Manager::TAB_STYLE,
  112.             ]
  113.         );
  114.         $this->add_control(
  115.             'border_radius',
  116.             [
  117.                 'label' => __( 'Border Radius', 'themeum-core' ),
  118.                 'type' => Controls_Manager::DIMENSIONS,
  119.                 'size_units' => [ 'px', '%' ],
  120.                 'selectors' => [
  121.                     '{{WRAPPER}} .blog-post-item-col .newskit-index-post' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
  122.                 ],
  123.             ]
  124.         );
  125.         $this->add_control(
  126.             'title_color',
  127.             [
  128.                 'label'     => __( 'Title Color', 'themeum-core' ),
  129.                 'type'      => Controls_Manager::COLOR,
  130.                 'scheme'    => [
  131.                         'type' => Scheme_Color::get_type(),
  132.                         'value' => Scheme_Color::COLOR_1,
  133.                     ],
  134.                 'selectors' => [
  135.                     '{{WRAPPER}} .newskit-post .content-item-title a' => 'color: {{VALUE}};',
  136.                 ],
  137.             ]
  138.         );
  139.         $this->add_group_control(
  140.             Group_Control_Typography::get_type(),
  141.             [
  142.                 'name'      => 'typography',
  143.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  144.                 'selector'  => '{{WRAPPER}} .newskit-post .content-item-title a',
  145.             ]
  146.         );
  147.         $this->end_controls_section();
  148.         # Title Section End
  149.  
  150.         #Pagination Section
  151.         $this->start_controls_section(
  152.             'section_pagination_style',
  153.             [
  154.                 'label'     => __( 'Pagination', 'themeum-core' ),
  155.                 'tab'       => Controls_Manager::TAB_STYLE,
  156.             ]
  157.         );
  158.  
  159.         $this->add_responsive_control(
  160.             'post_align',
  161.             [
  162.                 'label'     => __( 'Alignment', 'themeum-core' ),
  163.                 'type'      => Controls_Manager::CHOOSE,
  164.                 'options'   => [
  165.                     'left'      => [
  166.                         'title' => __( 'Left', 'themeum-core' ),
  167.                         'icon'  => 'fa fa-align-left',
  168.                     ],
  169.                     'center'    => [
  170.                         'title' => __( 'Center', 'themeum-core' ),
  171.                         'icon'  => 'fa fa-align-center',
  172.                     ],
  173.                     'right'     => [
  174.                         'title' => __( 'Right', 'themeum-core' ),
  175.                         'icon'  => 'fa fa-align-right',
  176.                     ],
  177.                     'justify'   => [
  178.                         'title' => __( 'Justified', 'themeum-core' ),
  179.                         'icon'  => 'fa fa-align-justify',
  180.                     ],
  181.                 ],
  182.                 'default'   => 'center',
  183.                 'selectors' => [
  184.                     '{{WRAPPER}} .themeum-pagination' => 'text-align: {{VALUE}}; display: inline-block; width: 100%;',
  185.                 ],
  186.             ]
  187.         );
  188.         $this->end_controls_section();
  189.  
  190.         #Subtitle Section
  191.         $this->start_controls_section(
  192.             'section_price_style',
  193.             [
  194.                 'label'     => __( 'Subtitle', 'themeum-core' ),
  195.                 'tab'       => Controls_Manager::TAB_STYLE,
  196.             ]
  197.         );
  198.  
  199.         $this->add_control(
  200.             'content_color',
  201.             [
  202.                 'label'     => __( 'Content Color', 'themeum-core' ),
  203.                 'type'      => Controls_Manager::COLOR,
  204.                 'scheme'    => [
  205.                         'type' => Scheme_Color::get_type(),
  206.                         'value' => Scheme_Color::COLOR_2,
  207.                     ],
  208.                 'selectors' => [
  209.                     '{{WRAPPER}} .newskit-post .entry-summary' => 'color: {{VALUE}};',
  210.                 ],
  211.             ]
  212.         );
  213.  
  214.         $this->add_group_control(
  215.             Group_Control_Typography::get_type(),
  216.             [
  217.                 'name'      => 'typography2',
  218.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_2,
  219.                 'selector'  => '{{WRAPPER}} .newskit-post .entry-summary',
  220.             ]
  221.         );
  222.     } # function _register_controls end
  223.  
  224.     protected function render( ) {
  225.  
  226.         $settings           = $this->get_settings();
  227.         $post_number        = $settings['post_number'];
  228.         $post_column        = $settings['post_column'];
  229.         $post_cat           = $settings['post_cat'];
  230.         $post_order_by      = $settings['post_order_by'];
  231.         $post_pagination    = $settings['post_pagination'];
  232.         $textlimit          = $settings['textlimit'];
  233.         $page_numb          = max( 1, get_query_var('paged') );
  234.  
  235.  
  236.         # Query Build
  237.         $args = array(
  238.                 'post_type'   =>  'post',
  239.                 'post_status' => 'publish',
  240.             );
  241.  
  242.         $defaults = array(
  243.             'posts_per_page'   => 8,
  244.             'post_type'        => 'post',
  245.         );
  246.  
  247.         $attr = wp_parse_args($args, $defaults);
  248.  
  249.         $posts = get_posts($attr);
  250.         if(count($posts) > 1){
  251.             global $post; ?>
  252.            
  253.             <div class="row">
  254.            
  255.                 <?php
  256.                 $j = 0;
  257.                 foreach($posts as $post){ setup_postdata( $post );  ?>
  258.  
  259.                     <!-- First Post -->
  260.                     <?php if ($j==0): ?>
  261.                         <div class="col-sm-8">
  262.                             <div class="my-custom-element <?php echo esc_attr($col); ?>">
  263.                                 <?php  if ( has_post_thumbnail()) { ?>
  264.                                     <a class="item-image"  href="<?php get_permalink(); ?>">
  265.                                         <?php echo get_the_post_thumbnail(get_the_ID(), 'full', array('class' => 'img-responsive')); ?>    
  266.                                     </a>
  267.                                 <?php } ?>
  268.                                 <h3><a href="<?php the_permalink( ); ?>"><?php the_title(); ?></a></h3>
  269.                                 <?php the_excerpt(); ?>
  270.                             </div>
  271.                         </div>
  272.                     <?php endif ?>
  273.                     <!-- End Post -->
  274.  
  275.                     <!-- Second Post -->
  276.                     <?php if ($j==1): ?>   
  277.                     <div class="col-sm-4">
  278.                     <?php endif ?>
  279.                         <?php if ($j == 1 || $j == 2 || $j == 3) { ?>
  280.                             <div class="blog-date-wrapper">
  281.                                 <time datetime="<?php echo get_the_date('Y-m-d') ?>">
  282.                                     <?php echo get_the_date(); ?>
  283.                                 </time>
  284.                             </div>
  285.                             <div class="my-custom-element <?php echo esc_attr($col); ?>">
  286.                                 <h3><a href="<?php the_permalink( ); ?>"><?php the_title(); ?></a></h3>
  287.                                 <?php //the_excerpt(); ?>
  288.                             </div> 
  289.                         <?php }  ?>
  290.                     <?php if ($j==3): ?>
  291.                     </div>
  292.                     <?php endif ?>
  293.                     <!-- End Post -->          
  294.             <?php if ($j == 4): ?>
  295.             </div><!-- row end -->
  296.             <div class="row">
  297.             <?php endif ?>
  298.  
  299.                 <?php if ($j == 4 || $j == 5 || $j == 6) { ?>
  300.                     <div class="col-sm-4">  
  301.                         <div class="my-custom-element <?php echo esc_attr($col); ?>">
  302.                             <h3><a href="<?php the_permalink( ); ?>"><?php the_title(); ?></a></h3>
  303.                             <?php the_excerpt(); ?>
  304.                         </div> 
  305.                     </div>
  306.                 <?php } ?>
  307.  
  308.             <?php  $j++; } wp_reset_postdata(); ?>
  309.             </div>
  310.         <?php }     ?>
  311.  
  312.     <?php } # Render end
  313.     protected function _content_template() { }
  314. }
  315.  
  316. Plugin::instance()->widgets_manager->register_widget_type( new Themeum_Widget_Posts_Featured_Content() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement