File: /home/nokatech/public_html/wp-content/themes/consultox/elementor_widget/blog_grid.php
<?php
use Elementor\Controls_Manager;
use Elementor\Controls_Stack;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Border;
use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Group_Control_Text_Shadow;
use Elementor\Plugin;
use Elementor\Utils;
class wpsection_blog_grid_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'wpsection_blog_grid';
}
public function get_title() {
return __( 'Blog Grid', 'wpsectionsupport' );
}
public function get_icon() {
return 'wpsd dashicons eicon-post';
}
public function get_keywords() {
return [ 'wpsection', 'blog_grid' ];
}
public function get_categories() {
return [ 'wpsection_category' ];
}
protected function _register_controls() {
$this->start_controls_section(
'blog_grid',
[
'label' => esc_html__( 'Blog Grid', 'consultox' ),
]
);
$this->add_control(
'style',
[
'label' => esc_html__( 'Choose Different Style', 'rashid' ),
'label_block' => true,
'type' => Controls_Manager::SELECT,
'default' => 'style1',
'options' => array(
'style1' => esc_html__( 'Choose Style 1', 'rashid' ),
'style2' => esc_html__( 'Choose Style 2', 'rashid' ),
'style3' => esc_html__( 'Choose Style 3', 'rashid' ),
),
]
);
$this->add_control(
'thumb',
[
'label' => esc_html__( 'Choose Post Image', 'consultox' ),
'label_block' => true,
'type' => Controls_Manager::SELECT,
'default' => 'style1',
'options' => array(
'style1' => esc_html__( 'Meta Box Image', 'consultox' ),
'style2' => esc_html__( 'Dafult Thumbnail', 'consultox' ),
'style2' => esc_html__( 'Dafult Thumbnail', 'consultox' ),
),
]
);
$this->add_control(
'bttn',
[
'label' => __( 'Button', 'consultox' ),
'type' => Controls_Manager::TEXT,
'dynamic' => [
'active' => true,
],
'placeholder' => esc_html__( 'Enter your Button Title', 'consultox' ),
'default' => esc_html__('Read More', 'consultox'),
]
);
$this->add_control(
'column',
[
'label' => esc_html__( 'Column', 'consultox' ),
'type' => Controls_Manager::SELECT,
'default' => '3',
'options' => array(
'12' => esc_html__( 'One Column', 'consultox' ),
'6' => esc_html__( 'Two Column', 'consultox' ),
'4' => esc_html__( 'Three Column', 'consultox' ),
'3' => esc_html__( 'Four Column', 'consultox' ),
'2' => esc_html__( 'Six Column', 'consultox' ),
),
]
);
$this->add_control(
'sec_class',
[
'label' => __( 'Section Class', 'rashid' ),
'type' => Controls_Manager::TEXTAREA,
'dynamic' => [
'active' => true,
],
'placeholder' => __( 'Enter Section Class', 'rashid' ),
]
);
$this->end_controls_section();
$this->start_controls_section(
'content_section',
[
'label' => __( 'Blog Block', 'consultox' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'text_limit',
[
'label' => esc_html__( 'Text Limit', 'consultox' ),
'type' => Controls_Manager::NUMBER,
'default' => 15,
'min' => 1,
'max' => 100,
'step' => 1,
]
);
$this->add_control(
'query_number',
[
'label' => esc_html__( 'Number of post', 'consultox' ),
'type' => Controls_Manager::NUMBER,
'default' => 3,
'min' => 1,
'max' => 100,
'step' => 1,
]
);
$this->add_control(
'query_orderby',
[
'label' => esc_html__( 'Order By', 'consultox' ),
'type' => Controls_Manager::SELECT,
'default' => 'date',
'options' => array(
'date' => esc_html__( 'Date', 'consultox' ),
'title' => esc_html__( 'Title', 'consultox' ),
'menu_order' => esc_html__( 'Menu Order', 'consultox' ),
'rand' => esc_html__( 'Random', 'consultox' ),
),
]
);
$this->add_control(
'query_order',
[
'label' => esc_html__( 'Order', 'consultox' ),
'type' => Controls_Manager::SELECT,
'default' => 'DESC',
'options' => array(
'DESc' => esc_html__( 'DESC', 'consultox' ),
'ASC' => esc_html__( 'ASC', 'consultox' ),
),
]
);
$this->add_control(
'query_exclude',
[
'label' => esc_html__( 'Exclude', 'consultox' ),
'type' => Controls_Manager::TEXT,
'description' => esc_html__( 'Exclude posts, pages, etc. by ID with comma separated.', 'consultox' ),
]
);
$this->add_control(
'query_category',
[
'type' => Controls_Manager::SELECT,
'label' => esc_html__('Category', 'consultox'),
'options' => get_blog_categories()
]
);
$this->add_control(
'show_pagination',
[
'label' => __( 'Enable/Disable Pagination', 'consultox' ),
'type' => Controls_Manager::SWITCHER,
'dynamic' => [
'active' => true,
],
'placeholder' => __( 'Enable/Disable Pagination', 'consultox' ),
]
);
$this->end_controls_section();
}
/**
* Render button widget output on the frontend.
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
* @access protected
*/
protected function render() {
$settings = $this->get_settings_for_display();
$paged = consultox_set($_POST, 'paged') ? esc_attr($_POST['paged']) : 1;
$this->add_render_attribute( 'wrapper', 'class', 'templatepath-consultox' );
$args = array(
'post_type' => 'post',
'posts_per_page' => consultox_set( $settings, 'query_number' ),
'orderby' => consultox_set( $settings, 'query_orderby' ),
'order' => consultox_set( $settings, 'query_order' ),
'paged' => $paged
);
if ( consultox_set( $settings, 'query_exclude' ) ) {
$settings['query_exclude'] = explode( ',', $settings['query_exclude'] );
$args['post__not_in'] = consultox_set( $settings, 'query_exclude' );
}
if( consultox_set( $settings, 'query_category' ) ) $args['category_name'] = consultox_set( $settings, 'query_category' );
$query = new \WP_Query( $args );
if ( $query->have_posts() )
{ ?>
<?php if ( 'style1' === $settings['style'] ) : ?>
<!--News Section-->
<section class="news-section">
<div class="auto-container">
<div class="row clearfix">
<?php while ( $query->have_posts() ) : $query->the_post();
$meta_image = get_post_meta( get_the_id(), 'meta_image', true );
?>
<div class="news-block col-md-<?php echo esc_attr($settings['column'], true );?> col-sm-6 col-xs-12">
<div class="inner-box hvr-float">
<div class="image">
<a href="<?php echo esc_url( the_permalink( get_the_id() ) );?>">
<?php if ( 'style1' === $settings['thumb'] ) : ?>
<img src="<?php echo wp_get_attachment_url($meta_image['id']);?>" alt="" />
<?php endif; ?>
<?php if ( 'style2' === $settings['thumb'] ) : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
</a>
<div class="post-date"><?php echo get_the_date(); ?></div>
</div>
<div class="lower-box">
<h3><a href="<?php echo esc_url( the_permalink( get_the_id() ) );?>"><?php the_title(); ?></a></h3>
<div class="text"><?php echo consultox_trim(get_the_content(), $settings['text_limit']); ?></div>
<a href="<?php echo esc_url( the_permalink( get_the_id() ) );?>" class="read-more"><?php echo $settings['bttn'];?></a>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
</section>
<!--End News Section-->
<?php endif ;?>
<?php }
wp_reset_postdata();
}
}
// Register widget
Plugin::instance()->widgets_manager->register( new \wpsection_blog_grid_Widget() );