<?php
/**
* Posts Widget
*/
namespace Elementor;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
class Cyarb_Posts extends Widget_Base {
public function get_name() {
return 'Cyarb_Posts';
}
public function get_title() {
return __( 'Posts', 'cyarb-toolkit' );
}
public function get_icon() {
return 'eicon-post-slider';
}
public function get_categories() {
return [ 'cyarb-elements' ];
}
protected function register_controls() {
$this->start_controls_section(
'Cyarb_Posts',
[
'label' => __( 'Cyarb Posts', 'cyarb-toolkit' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'title',
[
'label' => esc_html__( 'Title', 'cyarb-toolkit' ),
'type' => Controls_Manager::TEXT,
]
);
$this->add_control(
'title_tag',
[
'label' => esc_html__( 'Title Tag', 'cyarb-toolkit' ),
'type' => Controls_Manager::SELECT,
'options' => [
'h1' => esc_html__( 'h1', 'cyarb-toolkit' ),
'h2' => esc_html__( 'h2', 'cyarb-toolkit' ),
'h3' => esc_html__( 'h3', 'cyarb-toolkit' ),
'h4' => esc_html__( 'h4', 'cyarb-toolkit' ),
'h5' => esc_html__( 'h5', 'cyarb-toolkit' ),
'h6' => esc_html__( 'h6', 'cyarb-toolkit' ),
],
'default' => 'h2',
]
);
$this->add_control(
'desc',
[
'label'=>__('Add Description', 'cyarb-toolkit'),
'type'=>Controls_Manager:: WYSIWYG,
'description' => __('This text editor for p','cyarb-toolkit'),
]
);
$this->add_control(
'cat_name', [
'label' => esc_html__( 'Category', 'cyarb-toolkit' ),
'description' => esc_html__( 'Enter the category slugs separated by commas (Eg. cat1, cat2)', 'cyarb-toolkit' ),
'type' => Controls_Manager::TEXT,
'label_block' => true,
]
);
$this->add_control(
'order',
[
'label' => __( 'Posts Order By', 'cyarb-toolkit' ),
'type' => Controls_Manager::SELECT,
'options' => [
'DESC' => __( 'DESC', 'cyarb-toolkit' ),
'ASC' => __( 'ASC', 'cyarb-toolkit' ),
],
'default' => 'DESC',
]
);
$this->add_control(
'count',
[
'label' => __( 'Item', 'cyarb-toolkit' ),
'type' => Controls_Manager::NUMBER,
'default' => 3,
]
);
//Shape Images
$this->add_control(
'image_shape',
[
'label' => esc_html__( 'Hide Shapes?', 'cyarb-toolkit' ),
'type' => Controls_Manager::SWITCHER,
'label_on' => esc_html__( 'Show', 'cyarb-toolkit' ),
'label_off' => esc_html__( 'Hide', 'cyarb-toolkit' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->end_controls_section();
$this->start_controls_section(
'blog_style',
[
'label' => __( 'Color Controls', 'cyarb-toolkit' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'title_color',
[
'label' => esc_html__( 'Title Color', 'cyarb-toolkit' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .section-title h2, .section-title h3, .section-title h4, .section-title h5, .section-title h5, .section-title h6, .section-title h1' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => __( 'Title Typography', 'cyarb-toolkit' ),
'selector' => '{{WRAPPER}} .section-title h2, .section-title h3, .section-title h4, .section-title h5, .section-title h5, .section-title h6, .section-title h1',
]
);
$this->add_control(
'desc_color',
[
'label' => esc_html__( 'Description Color', 'cyarb-toolkit' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} p' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'desc_typography',
'label' => __( 'Description Typography', 'cyarb-toolkit' ),
'selector' => '{{WRAPPER}} p',
]
);
$this->add_control(
'tag_color',
[
'label' => esc_html__( 'Tag Color', 'cyarb-toolkit' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .single-blog-post .content .meta li a, .single-blog-post .content .meta li' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'tag_typography',
'label' => __( 'Tag Typography', 'cyarb-toolkit' ),
'selector' => '{{WRAPPER}} .single-blog-post .content .meta li a, .single-blog-post .content .meta li',
]
);
$this->add_control(
'post_title_color',
[
'label' => esc_html__( 'Post Title Color', 'cyarb-toolkit' ),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .single-blog-post .content h3 a' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'post_title_typography',
'label' => __( 'Post Title Typography', 'cyarb-toolkit' ),
'selector' => '{{WRAPPER}} .single-blog-post .content h3',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
global $cyarb_opt;
$count_tag = !empty($cyarb_opt['count_tag']) ? $cyarb_opt['count_tag'] : 1;
// Post Query
if( $settings['cat_name'] != '' ) {
$args = array(
'post_type' => 'post',
'posts_per_page'=> $settings['count'],
'order' => $settings['order'],
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => $settings['cat_name'],
'hide_empty' => false
)
)
);
} else {
$args = array(
'post_type' => 'post',
'posts_per_page' => $settings['count'],
'order' => $settings['order'],
'meta_key' => '_thumbnail_id',
);
}
$post_array = new \WP_Query( $args );
?>
<div class="blog-area pt-100 pb-75">
<div class="container">
<div class="section-title">
<<?php echo esc_attr($settings['title_tag']);?>><?php echo esc_html( $settings['title'] ); ?></<?php echo esc_attr($settings['title_tag']);?>>
<?php echo wp_kses_post( $settings['desc'] ); ?>
</div>
<div class="row justify-content-center">
<?php while($post_array->have_posts()): $post_array->the_post(); ?>
<div class="col-lg-4 col-md-6">
<div class="single-blog-post">
<div class="image">
<a href="<?php the_permalink(); ?>" class="d-block">
<img src="<?php echo get_the_post_thumbnail_url( get_the_ID(), 'cyarb_default_thumb' ); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
</a>
</div>
<div class="content">
<a href="<?php the_permalink(); ?>" class="link-btn"><i class="lni lni-chevron-right"></i></a>
<?php if( isset( $cyarb_opt['is_post_meta'] ) && $cyarb_opt['is_post_meta'] == true ) { ?>
<ul class="meta">
<li><i class="lni lni-calendar"></i> <?php echo get_the_date('M d, Y'); ?></li>
<li><i class="lni lni-comments"></i> <?php comments_number(); ?></li>
</ul><?php
} ?>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php echo esc_html(wp_trim_words( get_the_excerpt(), 20, '...' )); ?></p>
</div>
</div>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
<?php if ( 'yes' === $settings['image_shape'] ) : ?>
<div class="shape2"><img src="<?php echo esc_url(get_template_directory_uri() .'/assets/img/shape/shape2.png' ); ?>" alt="<?php echo esc_attr__( 'Shape', 'cyarb-toolkit' ); ?>"></div>
<div class="shape6"><img src="<?php echo esc_url(get_template_directory_uri() .'/assets/img/shape/shape6.png' ); ?>" alt="<?php echo esc_attr__( 'Shape', 'cyarb-toolkit' ); ?>"></div>
<?php endif; ?>
</div>
<?php
}
}
Plugin::instance()->widgets_manager->register_widget_type( new Cyarb_Posts );