File: /home/tvypkwena2lu/public_html/wp-content/plugins/widgets/gvs-new_event.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_GVSNewsEvents_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'gvs_newsevents';
}
public function get_title() {
return __( 'Theme Post List', '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(
'content_section',
[
'label' => __( 'Content', 'plugin-name' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'title',
[
'label' => __( 'Block Title', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'placeholder' => __( 'Upcoming', 'plugin-name' ),
'default' => 'Upcoming',
]
);
$this->add_control(
'sub_title',
[
'label' => __( 'Sub Title', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'placeholder' => __( 'Events', 'plugin-name' ),
'default' => 'Events',
]
);
$this->add_control(
'icon',
[
'label' => __( 'Select Icon', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::ICON,
'default' => '',
]
);
$this->add_control(
'custom_icon',
[
'label' => __( 'Custom Icon', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'default' => 'far fa-calendar-alt',
]
);
$this->add_control(
'post_from_cat',
[
'label' => __( 'Post Category ID', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'default' => __( '', 'plugin-name' ),
'placeholder'=>__( '1 or 1,2,3 etc.', 'plugin-name' ),
'description'=>__( 'Add Post Category ID to filter the post from that category only. you can insert single category ID or comma seperated category id', 'plugin-name' ),
]
);
$this->add_control(
'no_of_post',
[
'label' => __( 'No. of item to display', 'plugin-name' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'number',
'default' => 6,
]
);
$this->add_control(
'show_viewall',
[
'label' => __( 'Show - View All', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => __( 'Show', 'your-plugin' ),
'label_off' => __( 'Hide', 'your-plugin' ),
'return_value' => 'yes',
'default' => 'yes',
]
);
$this->add_control(
'website_link',
[
'label' => __( 'View All URL', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::URL,
'placeholder' => __( 'https://your-link.com', 'plugin-domain' ),
'show_external' => true,
'default' => [
'url' => '',
'is_external' => false,
'nofollow' => false,
],
'description'=>__( 'Type 2 to 3 letter will display post or page or paste full url', 'plugin-domain' ),
]
);
$this->add_control(
'testimonial_style',
[
'label' => __( 'Display Style', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'style1',
'options' => [
'style1' => __( 'Style1 | Home', 'plugin-domain' ),
/*'style2' => __( 'Style2 | Innerpage', 'plugin-domain' ),*/
'none' => __( 'None', 'plugin-domain' ),
],
]
);
$this->end_controls_section();
}
protected function render() {
//print_r($this->get_cus_taxonomies());
$settings = $this->get_settings_for_display();
//$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">
<div class="col-12">
<div class="text-center">
<h2 class="main-title mb-4">'.$icon.($settings['title'] ? $settings['title'] : '' ).' <span>'.($settings['sub_title'] ? $settings['sub_title'] : '' ).'</span></h2>
</div>
</div>
<div class="col-12">
<div class="blog-slider swiper-container">
<div class="swiper-wrapper">
';
while ( $newseventlist->have_posts() ) {
$newseventlist->the_post();
$content = get_the_content();
$first_img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
$first_img = $matches[1][0];
//echo $gvs_email;
echo '
<div class="swiper-slide">
<div class="blog-blk p-3">
<div class="row">
<div class="col-6">
<div class="blog-content-blk">
<div class="date-blk">
<div class="date-num">
'.get_the_time('j').'
</div>
'.get_the_time('M Y').'
</div>
<div class="blog-content">
<div class="blog-title">
<a href="'.get_permalink().'">'.wp_trim_words( get_the_title(), 10, '...' ).'</a>
</div>
<div class="blog-desc">
<p>'.wp_trim_words( get_the_excerpt(), 10, '...' ).'</p>
<a href="'.get_permalink().'" class="btn btn-primary">Read more <i class="fas fa-long-arrow-alt-right"></i></a>
</div>
</div>
</div>
</div>
<div class="col-6">
<div class="blog-img">
'.((has_post_thumbnail()) ? ('<a href="'.get_permalink().'">'.get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class'=>'img-fluid')).'</a>') : ($first_img ? ('<a href="'.get_permalink().'"><img class="img-fluid" src="'.$first_img.'"></a>') : '<a href="'.get_permalink().'"><img class="img-fluid" src="http://placehold.it/250x250"></a>')).'
</div>
</div>
</div>
</div>
</div>
';
}
echo '
</div>
<div class="text-center">
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
</div>
</div>
</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();
/*
'.(false ? ('<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>
*/
}
}