File: /home/tvypkwena2lu/public_html/wp-content/plugins/widgets/ele-post-caurosel.php
<?php
/**
* Elementor oEmbed Widget.
*
* Elementor widget that inserts an embbedable content into the page, from any given URL.
*
* @since 1.0.0
*/
class Elementor_Posts_Carousel_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'lae-posts-carousel';
}
public function get_title() {
return __( 'Theme Posts Carousel', 'plugin-name' );
}
public function get_icon() {
return 'eicon-post-list';
}
public function get_categories() {
return [ 'theme-specific-category' ];
}
public function get_cus_taxonomies() {
$args = array(
'public' => true,
'_builtin' => true,
);
$terms = get_taxonomies($args);
//print_r($terms);
return $terms;
}
protected function _register_controls() {
$this->start_controls_section(
'section_posts_carousel',
[
'label' => __('Posts Query', 'livemesh-el-addons'),
]
);
$this->add_control(
'post_types',
[
'label' => __('Post Types', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::SELECT2,
'default' => 'post',
'options' => lae_get_all_post_type_options(),
'multiple' => true
]
);
$this->add_control(
'tax_query',
[
'label' => __('Taxonomies', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::SELECT2,
'options' => lae_get_all_taxonomy_options(),
'multiple' => true,
'label_block' => true
]
);
$this->add_control(
'post_in',
[
'label' => __('Post In', 'livemesh-el-addons'),
'description' => __('Provide a comma separated list of Post IDs to display in the grid.', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::TEXT,
'label_block' => true
]
);
$this->add_control(
'posts_per_page',
[
'label' => __('Posts Per Page', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 6,
]
);
$this->add_control(
'advanced',
[
'label' => __('Advanced', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::HEADING,
]
);
$this->add_control(
'orderby',
[
'label' => __('Order By', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => array(
'none' => __('No order', 'livemesh-el-addons'),
'ID' => __('Post ID', 'livemesh-el-addons'),
'author' => __('Author', 'livemesh-el-addons'),
'title' => __('Title', 'livemesh-el-addons'),
'date' => __('Published date', 'livemesh-el-addons'),
'modified' => __('Modified date', 'livemesh-el-addons'),
'parent' => __('By parent', 'livemesh-el-addons'),
'rand' => __('Random order', 'livemesh-el-addons'),
'comment_count' => __('Comment count', 'livemesh-el-addons'),
'menu_order' => __('Menu order', 'livemesh-el-addons'),
'post__in' => __('By include order', 'livemesh-el-addons'),
),
'default' => 'date',
]
);
$this->add_control(
'order',
[
'label' => __('Order', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::SELECT,
'options' => array(
'ASC' => __('Ascending', 'livemesh-el-addons'),
'DESC' => __('Descending', 'livemesh-el-addons'),
),
'default' => 'DESC',
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_carousel_settings',
[
'label' => __('Carousel Settings', 'livemesh-el-addons'),
'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
]
);
$this->add_control(
'arrows',
[
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_off' => __('No', 'livemesh-el-addons'),
'label_on' => __('Yes', 'livemesh-el-addons'),
'return_value' => 'yes',
'default' => 'yes',
'label' => __('Prev/Next Arrows?', 'livemesh-el-addons'),
]
);
$this->add_control(
'dots',
[
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_off' => __('No', 'livemesh-el-addons'),
'label_on' => __('Yes', 'livemesh-el-addons'),
'return_value' => 'yes',
'default' => 'no',
'label' => __('Show dot indicators for navigation?', 'livemesh-el-addons'),
]
);
/*
$this->add_control(
'pause_on_hover',
[
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_off' => __('No', 'livemesh-el-addons'),
'label_on' => __('Yes', 'livemesh-el-addons'),
'return_value' => 'yes',
'default' => 'yes',
'label' => __('Pause on Hover?', 'livemesh-el-addons'),
]
);
*/
$this->add_control(
'autoplay',
[
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_off' => __('No', 'livemesh-el-addons'),
'label_on' => __('Yes', 'livemesh-el-addons'),
'return_value' => 'true',
'default' => 'true',
'label' => __('Autoplay?', 'livemesh-el-addons'),
'description' => __('Should the carousel autoplay as in a slideshow.', 'livemesh-el-addons'),
]
);
$this->add_control(
'autoplay_speed',
[
'label' => __('Autoplay speed in ms', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 300,
]
);
$this->add_control(
'animation_speed',
[
'label' => __('Autoplay animation speed in ms', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 300,
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_responsive',
[
'label' => __('Responsive Options', 'livemesh-el-addons'),
'tab' => \Elementor\Controls_Manager::TAB_SETTINGS,
]
);
$this->add_control(
'heading_desktop',
[
'label' => __('Desktop', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'after',
]
);
$this->add_control(
'gutter',
[
'label' => __('Gutter', 'livemesh-el-addons'),
'description' => __('Space between columns.', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 10,
'selectors' => [
'{{WRAPPER}} .lae-posts-carousel .lae-posts-carousel-item' => 'padding: {{VALUE}}px;',
],
]
);
$this->add_control(
'display_columns',
[
'label' => __('Columns per row', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 5,
'step' => 1,
'default' => 3,
]
);
$this->add_control(
'scroll_columns',
[
'label' => __('Columns to scroll', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 5,
'step' => 1,
'default' => 3,
]
);
$this->add_control(
'heading_tablet',
[
'label' => __('Tablet', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'after',
]
);
$this->add_control(
'tablet_gutter',
[
'label' => __('Gutter', 'livemesh-el-addons'),
'description' => __('Space between columns.', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 10,
'selectors' => [
'(tablet-){{WRAPPER}} .lae-posts-carousel .lae-posts-carousel-item' => 'padding: {{VALUE}}px;',
],
]
);
$this->add_control(
'tablet_display_columns',
[
'label' => __('Columns per row', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 5,
'step' => 1,
'default' => 2,
]
);
$this->add_control(
'tablet_scroll_columns',
[
'label' => __('Columns to scroll', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 5,
'step' => 1,
'default' => 2,
]
);
$this->add_control(
'tablet_width',
[
'label' => __('Tablet Resolution', 'livemesh-el-addons'),
'description' => __('The resolution to treat as a tablet resolution.', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 991,
]
);
$this->add_control(
'heading_mobile',
[
'label' => __('Mobile Phone', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::HEADING,
'separator' => 'after',
]
);
$this->add_control(
'mobile_gutter',
[
'label' => __('Mobile Gutter', 'livemesh-el-addons'),
'description' => __('Space between columns.', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 10,
'selectors' => [
'(mobile-){{WRAPPER}} .lae-posts-carousel .lae-posts-carousel-item' => 'padding: {{VALUE}}px;',
],
]
);
$this->add_control(
'mobile_display_columns',
[
'label' => __('Columns per row', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 3,
'step' => 1,
'default' => 1,
]
);
$this->add_control(
'mobile_scroll_columns',
[
'label' => __('Columns to scroll', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 3,
'step' => 1,
'default' => 1,
]
);
$this->add_control(
'mobile_width',
[
'label' => __('Mobile Resolution', 'livemesh-el-addons'),
'description' => __('The resolution to treat as a mobile resolution.', 'livemesh-el-addons'),
'type' => \Elementor\Controls_Manager::NUMBER,
'default' => 767,
]
);
$this->end_controls_section();
}
protected function render() {
//print_r($this->get_cus_taxonomies());
$settings = $this->get_settings_for_display();
$carousel_settings = [
'arrows' => ('yes' === $settings['arrows']),
'dots' => ('yes' === $settings['dots']),
'autoplay' => ('yes' === $settings['autoplay']),
'speed' => absint($settings['autoplay_speed']),
'animation_speed' => absint($settings['animation_speed']),
'pause_on_hover' => ('yes' === $settings['pause_on_hover']),
];
if('yes' === $settings['dots']) {
$carousel_settings= [
'pagination' => [
'el' => '.swiper-pagination',
'clickable'=> true,
],
];
}
if('yes' === $settings['arrows']) {
$carousel_settings= [
'navigation' => [
'nextEl' => '.swiper-button-next',
'prevEl' => '.swiper-button-prev',
],
];
}
$responsive_settings = [
'slidesPerView' => $settings['display_columns'],
'scroll_columns' => $settings['scroll_columns'],
'spaceBetween' => $settings['gutter'],
'breakpoints'=> [
$settings['mobile_width'] => [
'slidesPerView'=>$settings['mobile_display_columns'],
'spaceBetween'=>$settings['mobile_gutter'],
],
$settings['tablet_width'] => [
'slidesPerView'=>$settings['tablet_display_columns'],
'spaceBetween'=>$settings['tablet_gutter'],
],
],
/*'tablet_width' => $settings['tablet_width'],
'tablet_display_columns' => $settings['tablet_display_columns'],
'tablet_scroll_columns' => $settings['tablet_scroll_columns'],
'tablet_gutter' => $settings['tablet_gutter'],
'mobile_width' => $settings['mobile_width'],
'mobile_display_columns' => $settings['mobile_display_columns'],
'mobile_scroll_columns' => $settings['mobile_scroll_columns'],
'mobile_gutter' => $settings['mobile_gutter'], */
];
$carousel_settings = array_merge($carousel_settings, $responsive_settings);
$query_args = lae_build_query_args($settings);
$loop = new \WP_Query($query_args);
if ($loop->have_posts()) :
$post_id = get_the_ID();
$output = '<div id="lae-posts-carousel-' . uniqid()
. '" class="lae-posts-carousel news-slider2 swiper-container" data-swiper=\''.wp_json_encode($carousel_settings).'\'>';
$taxonomies[] = $settings['taxonomy_chosen'];
$output.= '<div class="swiper-wrapper">';
while ($loop->have_posts()) : $loop->the_post();
//$image=get_the_post_thumbnail(get_the_ID(), array(370,244), array('class'=>'img-fluid'));
$output.='<div class="swiper-slide">';
$output .= '
<div class="news-slide-blk">
'.(has_post_thumbnail() ? ('<div class="news-img"><a href="'.get_permalink().'">'.get_the_post_thumbnail(get_the_ID(), array(370,244), array('class'=>'w-100')).'</a></div>') : '<div class="news-img"><a href="'.get_permalink().'"><img class="w-100" src="http://placehold.it/370x244"></a></div>').'
<div class="news-content">
<h3><a href="'.get_permalink().'">'.wp_trim_words( get_the_title(), 10, '...' ).'</a></h3>
<p class="d-none">'.wp_trim_words( get_the_content(), 20, '...' ).'</p>
<div class="news-btn text-center">
<a href="'.get_permalink().'" class="btn btn-primary"> Read More <i class="fas fa-long-arrow-alt-right ml-1"></i></a>
</div>
</div>
</div>
';
$output.='</div>';
endwhile;
$output .= '</div>';
wp_reset_postdata();
$output.=(('yes' === $settings['arrows']) ? '<!-- If we need navigation buttons --><div class="swiper-button-prev"></div><div class="swiper-button-next"></div>' : '');
$output.=(('yes' === $settings['dots']) ? '<div class="pt-5"></div><div class="swiper-pagination"></div>' : '');
$output .= '</div><!-- .lae-posts-carousel -->';
$output .='
';
echo $output;
endif;
//$settings['testimonial_style']
/*
title
sub_title
icon
custom_icon
post_from_cat
no_of_post
website_link
show_viewall
*/
$style='';
//$posts_per_page='10';
$no_of_post = $settings['no_of_post'] ? $settings['no_of_post'] : 5;
if($settings['icon']) {
$icon='<i class="'.$settings['icon'].' mr-2"></i>';
} elseif($settings['custom_icon']) {
$icon='<i class="'.$settings['custom_icon'].' mr-2"></i>';
} else {
$icon='';
}
if($settings['show_viewall']==='yes') {
$readmore='';
if($settings['website_link']['url']) {
$target = $settings['website_link']['is_external'] ? ' target="_blank"' : '';
$nofollow = $settings['website_link']['nofollow'] ? ' rel="nofollow"' : '';
$readmore='<a title="'.$settings['list_title'].'" class="view-all-link" href="'.$settings['website_link']['url']. '"' . $target . $nofollow . '>View All<i class="fas fa-bars ml-1"></i></a>';
}
}
$args = array();
$cat='';
if($settings['post_from_cat']) {
$cat=$settings['post_from_cat'];
}
$args = array(
'post_type' => array('post'),
'post_status' => array('publish'),
'posts_per_page' => $no_of_post,
'cat'=>$cat
);
//echo '<pre>';
//print_r($args);
//echo '</pre>';
$newseventlist = new WP_Query( $args );
//var_dump($newseventlist);
if ( $newseventlist->have_posts() ) {
if($settings['testimonial_style']=='style1') {
echo '
<div class="row jusify-content-between align-items-center">
<div class="col-sm-8">
<div class="main-heading-small">
<h2>'.$icon.($settings['title'] ? $settings['title'] : '' ).' <span>'.($settings['sub_title'] ? $settings['sub_title'] : '' ).'</span></h2>
</div>
</div>
<div class="col-sm-4 text-sm-right">
'.$readmore.'
</div>
</div>
';
echo '
<div class="row">
<div class="col-12">
';
while ( $newseventlist->have_posts() ) {
$newseventlist->the_post();
//echo $gvs_email;
echo '
<div class="event-blk d-flex flex-row mt-3 pb-2">
'.(has_post_thumbnail() ? ('<div class="event-img mr-4"><a href="'.get_permalink().'">'.get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class'=>'img-fluid')).'</a></div>') : '<div class="event-img mr-4"><a href="'.get_permalink().'"><img class="img-fluid" src="http://placehold.it/350x350"></a></div>').'
<div class="event-content">
<h3><a href="'.get_permalink().'">'.wp_trim_words( get_the_title(), 10, '...' ).'</a></h3>
<p>'.wp_trim_words( get_the_content(), 20, '...' ).'</p>
<a href="'.get_permalink().'" class="read-more-link">Read More <i class="fas fa-long-arrow-alt-right ml-1"></i></a>
</div>
</div>
';
}
echo '
</div>
</div>
';
}
if($settings['testimonial_style']=='style2') {
echo '
<div class="row">
<div class="col-12">
<div class="main-heading text-center mb-4">
<h2>'.$icon.($settings['title'] ? $settings['title'] : '' ).' <span>'.($settings['sub_title'] ? $settings['sub_title'] : '' ).'</span></h2>
</div>
</div>
<div class="col-12">
<div class="news-slider swiper-container">
<div class="swiper-wrapper">
';
while ( $newseventlist->have_posts() ) {
$newseventlist->the_post();
echo '
<div class="swiper-slide">
<div class="news-slide-blk">
'.(has_post_thumbnail() ? ('<div class="news-img"><a href="'.get_permalink().'">'.get_the_post_thumbnail(get_the_ID(), array(370,244), array('class'=>'w-100')).'</a></div>') : '<div class="news-img"><a href="'.get_permalink().'"><img class="w-100" src="http://placehold.it/370x244"></a></div>').'
<div class="news-content">
<h3><a href="'.get_permalink().'">'.wp_trim_words( get_the_title(), 10, '...' ).'</a></h3>
<p>'.wp_trim_words( get_the_content(), 20, '...' ).'</p>
<div class="news-btn text-center">
<a href="'.get_permalink().'" class="btn btn-primary"> Read More <i class="fas fa-long-arrow-alt-right ml-1"></i></a>
</div>
</div>
</div>
</div>
';
}
echo '
</div>
<!-- If we need navigation buttons -->
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</div>
</div>
';
}
} else {
}
wp_reset_postdata();
}
}