Advertisement
rejuancse

themeum-latest-news

Apr 2nd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.81 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_Latest_Post_Content extends Widget_Base {
  8.  
  9.     public function get_name() {
  10.         return 'newskit-latest-post-content';
  11.     }
  12.  
  13.     public function get_title() {
  14.         return __( 'Themeum Latest 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.  
  35.         $this->add_control(
  36.             'post_style',
  37.             [
  38.                 'label'     => __( 'Style', 'themeum-core' ),
  39.                 'type'      => Controls_Manager::SELECT,
  40.                 'default'   => 'style1',
  41.                 'options'   => [
  42.                         'style1'        => __( 'Style One', 'themeum-core' ),
  43.                         'style2'        => __( 'Style Two', 'themeum-core' ),
  44.                         'style3'        => __( 'Style Three', 'themeum-core' ),
  45.                     ],
  46.             ]
  47.         );
  48.  
  49.         $this->add_control(
  50.             'post_column',
  51.             [
  52.                 'label'     => __( 'Number of Column', 'themeum-core' ),
  53.                 'type'      => Controls_Manager::SELECT,
  54.                 'options'   => [
  55.                         '12'    => __( 'One Column', 'themeum-core' ),
  56.                         '6'     => __( 'Two Column', 'themeum-core' ),
  57.                         '4'     => __( 'Three Column', 'themeum-core' ),
  58.                         '3'     => __( 'Four Column', 'themeum-core' ),
  59.                     ],
  60.                 'default'       => 4,
  61.                 'condition'     => [
  62.                     'post_style'    => 'style3',
  63.                 ],
  64.             ]
  65.         );
  66.  
  67.  
  68.  
  69.         $this->add_control(
  70.           'post_number',
  71.           [
  72.             'label'         => __( 'Number of Posts', 'themeum-core' ),
  73.             'type'          => Controls_Manager::NUMBER,
  74.             'label_block'   => true,
  75.             'default'       => __( '9', 'themeum-core' ),
  76.  
  77.           ]
  78.         );
  79.         $this->add_control(
  80.           'post_cat',
  81.           [
  82.              'label'    => __( 'Product Category', 'themeum-core' ),
  83.              'type'     => Controls_Manager::SELECT,
  84.              'options'  => themeum_cat_list( 'category' ),
  85.              'multiple' => true,
  86.              'default'  => 'allpost'
  87.           ]
  88.         );
  89.         $this->add_control(
  90.             'post_order_by',
  91.             [
  92.                 'label'     => __( 'Order', 'themeum-core' ),
  93.                 'type'      => Controls_Manager::SELECT,
  94.                 'default'   => 'DESC',
  95.                 'options'   => [
  96.                         'DESC'      => __( 'Descending', 'themeum-core' ),
  97.                         'ASC'       => __( 'Ascending', 'themeum-core' ),
  98.                     ],
  99.             ]
  100.         );
  101.         $this->add_control(
  102.           'textlimit',
  103.           [
  104.             'label'         => __( 'Text Limit Of Content', 'themeum-core' ),
  105.             'type'          => Controls_Manager::NUMBER,
  106.             'label_block'   => true,
  107.             'default'       => 280,
  108.           ]
  109.         );
  110.         $this->end_controls_section();
  111.  
  112.  
  113.         # Title Section
  114.         $this->start_controls_section(
  115.             'section_title_style',
  116.             [
  117.                 'label'     => __( 'Title', 'themeum-core' ),
  118.                 'tab'       => Controls_Manager::TAB_STYLE,
  119.             ]
  120.         );
  121.         $this->add_control(
  122.             'border_radius',
  123.             [
  124.                 'label' => __( 'Border Radius', 'themeum-core' ),
  125.                 'type' => Controls_Manager::DIMENSIONS,
  126.                 'size_units' => [ 'px', '%' ],
  127.                 'selectors' => [
  128.                     '{{WRAPPER}} .blog-post-item-col .newskit-index-post' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
  129.                 ],
  130.             ]
  131.         );
  132.         $this->add_control(
  133.             'title_color',
  134.             [
  135.                 'label'     => __( 'Title Color', 'themeum-core' ),
  136.                 'type'      => Controls_Manager::COLOR,
  137.                 'scheme'    => [
  138.                         'type' => Scheme_Color::get_type(),
  139.                         'value' => Scheme_Color::COLOR_1,
  140.                     ],
  141.                 'selectors' => [
  142.                     '{{WRAPPER}} .newskit-post .content-item-title a' => 'color: {{VALUE}};',
  143.                 ],
  144.             ]
  145.         );
  146.         $this->add_group_control(
  147.             Group_Control_Typography::get_type(),
  148.             [
  149.                 'name'      => 'typography',
  150.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_1,
  151.                 'selector'  => '{{WRAPPER}} .newskit-post .content-item-title a',
  152.             ]
  153.         );
  154.         $this->end_controls_section();
  155.         # Title Section End
  156.  
  157.         #Pagination Section
  158.         $this->start_controls_section(
  159.             'section_pagination_style',
  160.             [
  161.                 'label'     => __( 'Pagination', 'themeum-core' ),
  162.                 'tab'       => Controls_Manager::TAB_STYLE,
  163.             ]
  164.         );
  165.  
  166.         $this->add_responsive_control(
  167.             'post_align',
  168.             [
  169.                 'label'     => __( 'Alignment', 'themeum-core' ),
  170.                 'type'      => Controls_Manager::CHOOSE,
  171.                 'options'   => [
  172.                     'left'      => [
  173.                         'title' => __( 'Left', 'themeum-core' ),
  174.                         'icon'  => 'fa fa-align-left',
  175.                     ],
  176.                     'center'    => [
  177.                         'title' => __( 'Center', 'themeum-core' ),
  178.                         'icon'  => 'fa fa-align-center',
  179.                     ],
  180.                     'right'     => [
  181.                         'title' => __( 'Right', 'themeum-core' ),
  182.                         'icon'  => 'fa fa-align-right',
  183.                     ],
  184.                     'justify'   => [
  185.                         'title' => __( 'Justified', 'themeum-core' ),
  186.                         'icon'  => 'fa fa-align-justify',
  187.                     ],
  188.                 ],
  189.                 'default'   => 'center',
  190.                 'selectors' => [
  191.                     '{{WRAPPER}} .themeum-pagination' => 'text-align: {{VALUE}}; display: inline-block; width: 100%;',
  192.                 ],
  193.             ]
  194.         );
  195.         $this->end_controls_section();
  196.  
  197.         #Subtitle Section
  198.         $this->start_controls_section(
  199.             'section_price_style',
  200.             [
  201.                 'label'     => __( 'Subtitle', 'themeum-core' ),
  202.                 'tab'       => Controls_Manager::TAB_STYLE,
  203.             ]
  204.         );
  205.  
  206.         $this->add_control(
  207.             'content_color',
  208.             [
  209.                 'label'     => __( 'Content Color', 'themeum-core' ),
  210.                 'type'      => Controls_Manager::COLOR,
  211.                 'scheme'    => [
  212.                         'type' => Scheme_Color::get_type(),
  213.                         'value' => Scheme_Color::COLOR_2,
  214.                     ],
  215.                 'selectors' => [
  216.                     '{{WRAPPER}} .newskit-post .entry-summary' => 'color: {{VALUE}};',
  217.                 ],
  218.             ]
  219.         );
  220.  
  221.         $this->add_group_control(
  222.             Group_Control_Typography::get_type(),
  223.             [
  224.                 'name'      => 'typography2',
  225.                 'scheme'    => Scheme_Typography::TYPOGRAPHY_2,
  226.                 'selector'  => '{{WRAPPER}} .newskit-post .entry-summary',
  227.             ]
  228.         );
  229.     } # function _register_controls end
  230.  
  231.     protected function render( ) {
  232.  
  233.         $settings           = $this->get_settings();
  234.  
  235.         $post_style         = $settings['post_style'];
  236.         $textlimit          = $settings['textlimit'];
  237.         $post_number        = $settings['post_number'];
  238.         $post_cat           = $settings['post_cat'];
  239.         $post_order_by      = $settings['post_order_by'];
  240.         $page_numb          = max( 1, get_query_var('paged') );
  241.  
  242.         # Query Build
  243.         $args = array(
  244.                 'post_type'         =>  'post',
  245.                 'post_status'       => 'publish',
  246.                 'posts_per_page'    => $post_number,
  247.                 'order'             => $post_order_by,
  248.                 'tax_query' => array(
  249.                     array(
  250.                         'taxonomy' => 'category',
  251.                         'field'    => 'slug',
  252.                         'terms'    => esc_attr($post_cat),
  253.                     ),
  254.                 ),
  255.             );
  256.  
  257.         $defaults = array(
  258.             'posts_per_page'   => $post_number,
  259.             'post_type'        => 'post',
  260.         );
  261.  
  262.         $attr = wp_parse_args($args, $defaults);
  263.  
  264.         $posts = get_posts($attr);
  265.         if(count($posts)){
  266.             global $post; ?>
  267.  
  268.  
  269.  
  270.             <?php  if ($post_style == 'style1') { ?>
  271.                
  272.                     <?php
  273.                     $j = 1;
  274.                     foreach($posts as $post){ setup_postdata( $post );  ?> 
  275.                         <?php if ( $j === 1 ) { ?>
  276.                             <div class="addon-article intro-item-wrapper ">
  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 class="fa fa-facebook"></a>
  282.                                             <a class="fa fa-twitter"></a>
  283.                                             <a class="fa fa-google-plus"></a>
  284.                                         </div>
  285.                                     </div>
  286.                                     <a href="<?php get_permalink(); ?>" class="img-wrapper">
  287.                                         <?php echo get_the_post_thumbnail(get_the_ID(), 'newskit-latest-post', array('class' => 'img-responsive')); ?>
  288.                                     </a>
  289.                                 </div>
  290.                                 <div class="article-details ">
  291.  
  292.                                     <ul class="newskit-post-category">
  293.                                         <?php if ( get_theme_mod( 'blog_category', true ) ): ?>
  294.                                             <li class="meta-category"><?php printf(esc_html__('%s', 'themeum-core'), get_the_category_list(' ')); ?></li>
  295.                                         <?php endif; ?>
  296.                                     </ul>
  297.  
  298.                                     <div class="article-meta">
  299.                                         <span class="meta-date" itemprop="dateCreated"><?php echo get_the_date(); ?></span>
  300.                                     </div>
  301.  
  302.                                     <h3 class="article-title">
  303.                                         <a href="<?php the_permalink( ); ?>" ><?php the_title(); ?></a>
  304.                                     </h3>
  305.  
  306.                                     <?php
  307.                                         if ( $textlimit ) {
  308.                                             if (get_theme_mod( 'blog_intro_text_en', true )) {
  309.                                                 echo newskit_excerpt_max_charlength($textlimit);
  310.                                             }
  311.                                         }
  312.                                     ?>
  313.  
  314.                                 </div>
  315.                             </div> 
  316.                         <?php }else { ?>
  317.                             <div class="section-content-second">
  318.                                 <div class="article-details">
  319.                                     <div class="article-meta">
  320.                                         <span class="meta-date" itemprop="dateCreated"><?php echo get_the_date(); ?></span>
  321.                                     </div>
  322.                                     <h3 class="article-title">
  323.                                         <a href="<?php the_permalink( ); ?>" itemprop="url"><?php the_title(); ?></a>
  324.                                     </h3>
  325.                                 </div>
  326.                             </div>
  327.                         <?php }  ?>
  328.                     <?php } ?>
  329.                
  330.             <?php }else if ($post_style == 'style2') {
  331.  
  332.                 $j = 0; ?>
  333.  
  334.                 <?php foreach($posts as $post){ setup_postdata( $post );  ?>
  335.                     <!-- First Post -->
  336.                     <?php if ( $j==0 ) { ?>
  337.                         <div class="newskit-image-wrap latest-post-section">
  338.                             <div class="addon-article leading-item">
  339.  
  340.                                 <div class="article-image-wrap">
  341.                                     <div class="post-share-social">
  342.                                         <span class="share-button"><i class="fa fa-share-square-o"></i></span>
  343.                                         <div class="post-share-social-others">
  344.                                             <a class="fa fa-facebook"></a>
  345.                                             <a class="fa fa-twitter"></a>
  346.                                             <a class="fa fa-google-plus"></a>
  347.                                         </div>
  348.                                     </div>
  349.                                     <?php  if ( has_post_thumbnail()) { ?>
  350.                                         <a class="item-image"  href="<?php get_permalink(); ?>">
  351.                                             <?php echo get_the_post_thumbnail(get_the_ID(), 'full', array('class' => 'img-responsive')); ?>    
  352.                                         </a>
  353.                                     <?php } ?>
  354.                                 </div>
  355.  
  356.                                 <div class="article-details">
  357.                                     <ul class="newskit-post-category">
  358.                                         <?php if ( get_theme_mod( 'blog_category', true ) ): ?>
  359.                                             <li class="meta-category"><?php printf(esc_html__('%s', 'themeum-core'), get_the_category_list(' ')); ?></li>
  360.                                         <?php endif; ?>
  361.                                     </ul>
  362.  
  363.                                     <div class="article-meta">
  364.                                         <span class="meta-date"><?php echo get_the_date(); ?></span>
  365.                                     </div>
  366.                                     <h3 class="article-title">
  367.                                         <a href="<?php the_permalink( ); ?>" itemprop="url"><?php the_title(); ?></a>
  368.                                     </h3>
  369.                                 </div>
  370.  
  371.                                
  372.                             </div>
  373.                         </div>
  374.                     <?php } else{ ?>
  375.  
  376.  
  377.                         <div class="section-content-second">
  378.                             <div class="article-details">
  379.                                 <ul class="newskit-post-category">
  380.                                     <?php if ( get_theme_mod( 'blog_category', true ) ): ?>
  381.                                         <li class="meta-category"><?php printf(esc_html__('%s', 'themeum-core'), get_the_category_list(' ')); ?></li>
  382.                                     <?php endif; ?>
  383.                                 </ul>
  384.                                 <div class="article-meta">
  385.                                     <span class="meta-date" itemprop="dateCreated"><?php echo get_the_date(); ?></span>
  386.                                 </div>
  387.                                 <h3 class="article-title">
  388.                                     <a href="<?php the_permalink( ); ?>" itemprop="url"><?php the_title(); ?></a>
  389.                                 </h3>
  390.                             </div>
  391.                         </div>
  392.  
  393.                     <?php } $j++; wp_reset_postdata(); ?>
  394.                     <!-- End Post -->
  395.                 <?php } ?> <!-- End Foreach Loop -->
  396.             <?php } ?> <!-- End elseif Loop -->
  397.  
  398.  
  399.         <?php } ?>
  400.  
  401.     <?php } # Render end
  402.     protected function _content_template() { }
  403. }
  404.  
  405. Plugin::instance()->widgets_manager->register_widget_type( new Themeum_Widget_Latest_Post_Content() );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement