first commit
This commit is contained in:
295
wp-content/plugins/thinkai-plugin/elementor/blog_carousel.php
Normal file
295
wp-content/plugins/thinkai-plugin/elementor/blog_carousel.php
Normal file
@@ -0,0 +1,295 @@
|
||||
<?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_Carousel 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_carousel';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Carousel', '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' ];
|
||||
}
|
||||
|
||||
public function get_script_depends() {
|
||||
wp_register_script( 'blog-carousel-script', YT_URL . 'assets/js/feature-carousel.js', [ 'elementor-frontend' ], '1.0.0', true );
|
||||
return [ 'blog-carousel-script' ];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_carousel',
|
||||
[
|
||||
'label' => esc_html__( 'Thinkai Blog Carousel', '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()
|
||||
]
|
||||
);
|
||||
$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');
|
||||
|
||||
$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() )
|
||||
|
||||
{ ?>
|
||||
|
||||
<!--Start Blog Style2-->
|
||||
<section class="blog-style2 p-0 m-0">
|
||||
<div class="container">
|
||||
|
||||
<div class="owl-carousel owl-theme thm-owl__carousel blog-style2__carousel" data-owl-options='{
|
||||
"loop": true,
|
||||
"autoplay": false,
|
||||
"margin": 30,
|
||||
"nav": false,
|
||||
"dots": false,
|
||||
"smartSpeed": 500,
|
||||
"autoplayTimeout": 10000,
|
||||
"navText": ["<span class=\"left icon-right-arrow-4\"></span>","<span class=\"right icon-right-arrow-4\"></span>"],
|
||||
"responsive": {
|
||||
"0": {
|
||||
"items": 1
|
||||
},
|
||||
"768": {
|
||||
"items": 1
|
||||
},
|
||||
"992": {
|
||||
"items": 2
|
||||
},
|
||||
"1200": {
|
||||
"items": 3
|
||||
}
|
||||
}
|
||||
}'>
|
||||
|
||||
<?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="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>
|
||||
<!--End Single Blog Style2-->
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!--End Blog Style2-->
|
||||
|
||||
<?php }
|
||||
wp_reset_postdata();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user