454 lines
16 KiB
PHP
454 lines
16 KiB
PHP
<?php
|
|
|
|
namespace THINKAIPLUGIN\Element;
|
|
|
|
use Elementor\Controls_Manager;
|
|
use Elementor\Controls_Stack;
|
|
use Elementor\Group_Control_Typography;
|
|
use Elementor\Group_Control_Border;
|
|
use Elementor\Repeater;
|
|
use Elementor\Widget_Base;
|
|
use Elementor\Utils;
|
|
use Elementor\Group_Control_Text_Shadow;
|
|
use \Elementor\Group_Control_Box_Shadow;
|
|
use \Elementor\Group_Control_Background;
|
|
use \Elementor\Group_Control_Image_Size;
|
|
use \Elementor\Group_Control_Text_Stroke;
|
|
use Elementor\Plugin;
|
|
|
|
/**
|
|
* Elementor button widget.
|
|
* Elementor widget that displays a button with the ability to control every
|
|
* aspect of the button design.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class Blog_Grid extends Widget_Base {
|
|
|
|
/**
|
|
* Get widget name.
|
|
* Retrieve button widget name.
|
|
*
|
|
* @since 1.0.0
|
|
* @access public
|
|
* @return string Widget name.
|
|
*/
|
|
public function get_name() {
|
|
return 'thinkai_blog_grid';
|
|
}
|
|
|
|
/**
|
|
* Get widget title.
|
|
* Retrieve button widget title.
|
|
*
|
|
* @since 1.0.0
|
|
* @access public
|
|
* @return string Widget title.
|
|
*/
|
|
public function get_title() {
|
|
return esc_html__( 'Thinkai Blog Grid', 'thinkai' );
|
|
}
|
|
|
|
/**
|
|
* Get widget icon.
|
|
* Retrieve button widget icon.
|
|
*
|
|
* @since 1.0.0
|
|
* @access public
|
|
* @return string Widget icon.
|
|
*/
|
|
public function get_icon() {
|
|
return 'eicon-gallery-grid';
|
|
}
|
|
|
|
/**
|
|
* Get widget categories.
|
|
* Retrieve the list of categories the button widget belongs to.
|
|
* Used to determine where to display the widget in the editor.
|
|
*
|
|
* @since 2.0.0
|
|
* @access public
|
|
* @return array Widget categories.
|
|
*/
|
|
public function get_categories() {
|
|
return [ 'thinkai' ];
|
|
}
|
|
|
|
/**
|
|
* Register button widget controls.
|
|
* Adds different input fields to allow the user to change and customize the widget settings.
|
|
*
|
|
* @since 1.0.0
|
|
* @access protected
|
|
*/
|
|
protected function register_controls() {
|
|
$this->start_controls_section(
|
|
'blog_grid',
|
|
[
|
|
'label' => esc_html__( 'Thinkai Blog Grid', 'thinkai' ),
|
|
]
|
|
);
|
|
$this->add_control(
|
|
'layout_control',
|
|
[
|
|
'label' => esc_html__( 'Layout Style', 'thinkai' ),
|
|
'label_block' => true,
|
|
'type' => Controls_Manager::SELECT,
|
|
'default' => '1',
|
|
'options' => array(
|
|
'1' => esc_html__( 'Style One', 'thinkai'),
|
|
'2' => esc_html__( 'Style Two', 'thinkai'),
|
|
'3' => esc_html__( 'Style Three', 'thinkai'),
|
|
),
|
|
]
|
|
);
|
|
//Author
|
|
$this->add_control(
|
|
'author',
|
|
[
|
|
'label' => esc_html__( 'Show Author', 'thinkai' ),
|
|
'type' => Controls_Manager::SWITCHER,
|
|
'label_on' => esc_html__( 'On', 'thinkai' ),
|
|
'label_off' => esc_html__( 'Off', 'thinkai' ),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
//Date
|
|
$this->add_control(
|
|
'date',
|
|
[
|
|
'label' => esc_html__( 'Show Date', 'thinkai' ),
|
|
'type' => Controls_Manager::SWITCHER,
|
|
'label_on' => esc_html__( 'On', 'thinkai' ),
|
|
'label_off' => esc_html__( 'Off', 'thinkai' ),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
//category
|
|
$this->add_control(
|
|
'category',
|
|
[
|
|
'label' => esc_html__( 'Show category', 'thinkai' ),
|
|
'type' => Controls_Manager::SWITCHER,
|
|
'label_on' => esc_html__( 'On', 'thinkai' ),
|
|
'label_off' => esc_html__( 'Off', 'thinkai' ),
|
|
'return_value' => 'yes',
|
|
'default' => 'yes',
|
|
]
|
|
);
|
|
|
|
$this->add_control(
|
|
'query_number',
|
|
[
|
|
'label' => esc_html__( 'Number of post', 'thinkai' ),
|
|
'type' => Controls_Manager::NUMBER,
|
|
'default' => 3,
|
|
'min' => 1,
|
|
'max' => 100,
|
|
'step' => 1,
|
|
]
|
|
);
|
|
$this->add_control(
|
|
'query_orderby',
|
|
[
|
|
'label' => esc_html__( 'Order By', 'thinkai' ),
|
|
'label_block' => true,
|
|
'type' => Controls_Manager::SELECT,
|
|
'default' => 'date',
|
|
'options' => array(
|
|
'date' => esc_html__( 'Date', 'thinkai' ),
|
|
'title' => esc_html__( 'Title', 'thinkai' ),
|
|
'menu_order' => esc_html__( 'Menu Order', 'thinkai' ),
|
|
'rand' => esc_html__( 'Random', 'thinkai' ),
|
|
),
|
|
]
|
|
);
|
|
$this->add_control(
|
|
'query_order',
|
|
[
|
|
'label' => esc_html__( 'Order', 'thinkai' ),
|
|
'label_block' => true,
|
|
'type' => Controls_Manager::SELECT,
|
|
'default' => 'DESC',
|
|
'options' => array(
|
|
'DESC' => esc_html__( 'DESC', 'thinkai' ),
|
|
'ASC' => esc_html__( 'ASC', 'thinkai' ),
|
|
),
|
|
]
|
|
);
|
|
$this->add_control(
|
|
'query_category',
|
|
[
|
|
'type' => Controls_Manager::SELECT,
|
|
'label' => esc_html__('Category', 'thinkai'),
|
|
'label_block' => true,
|
|
'multiple' => true,
|
|
'options' => get_blog_categories()
|
|
]
|
|
);
|
|
|
|
//Pagination
|
|
$this->add_control(
|
|
'show_pagination',
|
|
[
|
|
'label' => __( 'Enable/Disable Pagination Style', 'thinkai' ),
|
|
'type' => Controls_Manager::SWITCHER,
|
|
'label_on' => __( 'Show', 'thinkai' ),
|
|
'label_off' => __( 'Hide', 'thinkai' ),
|
|
'return_value' => 'yes',
|
|
'default' => 'no',
|
|
'condition' => ['layout_control' => ['1','3'] ],
|
|
]
|
|
);
|
|
$this->end_controls_section();
|
|
|
|
/**Grid Setting Start**/
|
|
$this->start_controls_section(
|
|
'grid',
|
|
[
|
|
'label' => esc_html__( 'Grid Setting', 'thinkai' ),
|
|
]
|
|
);
|
|
$this->add_control(
|
|
'col_grid',
|
|
[
|
|
'label' => esc_html__( 'Choose Column', 'thinkai' ),
|
|
'label_block' => true,
|
|
'type' => Controls_Manager::SELECT,
|
|
'default' => 'three',
|
|
'options' => array(
|
|
'one' => esc_html__( 'One Column Grid ', 'thinkai'),
|
|
'two' => esc_html__( 'Two Column Grid', 'thinkai' ),
|
|
'three' => esc_html__( 'Three Column Grid', 'thinkai' ),
|
|
'four' => esc_html__( 'Four Column Grid', 'thinkai' ),
|
|
'five' => esc_html__( 'Six Column Grid', 'thinkai' ),
|
|
),
|
|
]
|
|
);
|
|
$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();
|
|
$allowed_tags = wp_kses_allowed_html('post');
|
|
$layout = $settings[ 'layout_control' ];
|
|
|
|
$grid_col = $settings['col_grid'];
|
|
if( $grid_col == 'one' ){
|
|
$classes = 'col-xl-12 col-lg-12 col-md-12 col-sm-12';
|
|
}elseif( $grid_col == 'two' ){
|
|
$classes = 'col-xl-6 col-lg-6 col-md-12 col-sm-12';
|
|
}elseif( $grid_col == 'four' ){
|
|
$classes = 'col-xl-3 col-lg-3 col-md-12 col-sm-12';
|
|
}elseif( $grid_col == 'five' ){
|
|
$classes = 'col-xl-2 col-lg-2 col-md-12 col-sm-12';
|
|
}else{
|
|
$classes = 'col-xl-4 col-lg-4 col-md-12 col-sm-12';
|
|
};
|
|
|
|
$category = $settings[ 'category' ];
|
|
$date = $settings[ 'date' ];
|
|
$author = $settings[ 'author' ];
|
|
|
|
$paged = get_query_var('paged');
|
|
$paged = thinkai_set($_REQUEST, 'paged') ? esc_attr($_REQUEST['paged']) : $paged;
|
|
|
|
$this->add_render_attribute( 'wrapper', 'class', 'templatepath-thinkai' );
|
|
$argst = array(
|
|
'post_type' => 'post',
|
|
'posts_per_page' => thinkai_set( $settings, 'query_number' ),
|
|
'orderby' => thinkai_set( $settings, 'query_orderby' ),
|
|
'order' => thinkai_set( $settings, 'query_order' ),
|
|
'paged' => $paged
|
|
);
|
|
if( thinkai_set( $settings, 'query_category' ) ) $args['category_name'] = thinkai_set( $settings, 'query_category' );
|
|
$query = new \WP_Query( $argst );
|
|
if ( $query->have_posts() )
|
|
|
|
{ ?>
|
|
|
|
|
|
<?php if( $layout == 3 ): ?>
|
|
|
|
<!--Start Blog Page Two-->
|
|
<section class="blog-page-two p-0 m-0">
|
|
<div class="row">
|
|
<?php
|
|
global $post;
|
|
while ( $query->have_posts() ) : $query->the_post();
|
|
$post_thumbnail_id = get_post_thumbnail_id($post->ID);
|
|
$post_thumbnail_url = wp_get_attachment_url($post_thumbnail_id);
|
|
?>
|
|
<!--Start Single Blog Style2-->
|
|
<div class="<?php echo esc_attr( $classes );?>">
|
|
<div class="blog-style2-single-outer-box hover-background-active">
|
|
<div class="blog-style2__single">
|
|
<div class="blog-style2__single-title">
|
|
<h3><a href="<?php echo esc_url( get_the_permalink( get_the_id() ) );?>"><?php the_title(); ?></a> </h3>
|
|
</div>
|
|
|
|
<?php if( $category == 'yes' && has_category() ){?>
|
|
<div class="blog-style2__single-category">
|
|
<span><?php the_category(' ');?></span>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="blog-style2__single-post">
|
|
<?php if( $author == 'yes' || $date == 'yes' ){ ?>
|
|
<div class="author-box">
|
|
<?php if( $author == 'yes'){?><h5><a href="<?php echo esc_url(get_author_posts_url( get_the_author_meta('ID') )); ?>"><?php the_author(); ?></a></h5><?php } ?>
|
|
<?php if( $date == 'yes' ){?><p><?php echo get_the_date(''); ?></p><?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="btn-box">
|
|
<a href="<?php echo esc_url( get_the_permalink( get_the_id() ) );?>">
|
|
<span class="icon-right-arrow1"></span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if($post_thumbnail_url){ ?>
|
|
<div class="blog-style2__single-overlay">
|
|
<div class="blog-style2__single-overlay__bg" data-src="<?php echo esc_url($post_thumbnail_url); ?>"></div>
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--End Single Blog Style2-->
|
|
<?php endwhile; ?>
|
|
</div>
|
|
|
|
<?php if($settings['show_pagination']){ ?>
|
|
<div class="styled-pagination-style2 clearfix">
|
|
<?php thinkai_the_pagination2(array('total'=>$query->max_num_pages, 'next_text' => 'Next Page <i class="icon-right-arrow1 right"></i> ', 'prev_text' => '<i class="icon-left-arrow1 left"></i> Prev Page')); ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
</section>
|
|
<!--End Blog Page Two-->
|
|
|
|
<?php elseif( $layout == 2 ): ?>
|
|
|
|
<!--Start Blog Style1-->
|
|
<section class="blog-style1 p-0 m-0">
|
|
<div class="row">
|
|
<?php
|
|
while ( $query->have_posts() ) : $query->the_post();
|
|
?>
|
|
<!--Start Blog Style1 Single-->
|
|
<div class="<?php echo esc_attr( $classes );?>">
|
|
<div class="blog-style1__single blog-style1__single--style2">
|
|
<?php if(has_post_thumbnail()){ ?>
|
|
<div class="blog-style1__single-img">
|
|
<?php the_post_thumbnail('thinkai_370x320'); ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="blog-style1__single-content">
|
|
<div class="blog-style1__single-content-top">
|
|
<?php if( $author == 'yes' || $date == 'yes' ){ ?>
|
|
<div class="text-box">
|
|
<?php if( $author == 'yes'){?><h4><?php the_author(); ?></h4><?php } ?>
|
|
<?php if( $date == 'yes' ){?><p><?php echo get_the_date(''); ?></p><?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="btn-box">
|
|
<a href="<?php echo esc_url( get_the_permalink( get_the_id() ) );?>"><span class="icon-right-arrow1"></span></a>
|
|
</div>
|
|
</div>
|
|
<h2>
|
|
<a href="<?php echo esc_url( get_the_permalink( get_the_id() ) );?>">
|
|
<?php the_title(); ?>
|
|
</a>
|
|
</h2>
|
|
|
|
<?php if( $category == 'yes' && has_category() ){?>
|
|
<div class="category-box">
|
|
<?php the_category(' ');?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--End Blog Style1 Single-->
|
|
<?php endwhile; ?>
|
|
</div>
|
|
</section>
|
|
<!--End Blog Style1-->
|
|
|
|
<?php else: ?>
|
|
|
|
<!--Start Blog Style1-->
|
|
<section class="blog-style1 p-0 m-0">
|
|
<div class="row">
|
|
<?php
|
|
while ( $query->have_posts() ) : $query->the_post();
|
|
?>
|
|
<!--Start Blog Style1 Single-->
|
|
<div class="<?php echo esc_attr( $classes );?>">
|
|
<div class="blog-style1__single">
|
|
<?php if(has_post_thumbnail()){ ?>
|
|
<div class="blog-style1__single-img">
|
|
<?php the_post_thumbnail('thinkai_370x320'); ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="blog-style1__single-content">
|
|
<div class="blog-style1__single-content-top">
|
|
<?php if( $author == 'yes' || $date == 'yes' ){ ?>
|
|
<div class="text-box">
|
|
<?php if( $author == 'yes'){?><h4><?php the_author(); ?></h4><?php } ?>
|
|
<?php if( $date == 'yes' ){?><p><?php echo get_the_date(''); ?></p><?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="btn-box">
|
|
<a href="<?php echo esc_url( get_the_permalink( get_the_id() ) );?>"><span class="icon-right-arrow1"></span></a>
|
|
</div>
|
|
</div>
|
|
<h2>
|
|
<a href="<?php echo esc_url( get_the_permalink( get_the_id() ) );?>">
|
|
<?php the_title(); ?>
|
|
</a>
|
|
</h2>
|
|
|
|
<?php if( $category == 'yes' && has_category() ){?>
|
|
<div class="category-box">
|
|
<?php the_category(' ');?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!--End Blog Style1 Single-->
|
|
<?php endwhile; ?>
|
|
|
|
<?php if($settings['show_pagination']){ ?>
|
|
<div class="styled-pagination-style2 clearfix">
|
|
<?php thinkai_the_pagination2(array('total'=>$query->max_num_pages, 'next_text' => 'Next Page <i class="icon-right-arrow1 right"></i> ', 'prev_text' => '<i class="icon-left-arrow1 left"></i> Prev Page')); ?>
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
</section>
|
|
<!--End Blog Style1-->
|
|
|
|
<?php endif; ?>
|
|
<?php }
|
|
wp_reset_postdata();
|
|
}
|
|
}
|