Created
February 23, 2021 12:40
-
-
Save asifpix/06c04dc68c2e02765de8104771be974a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Travelux_Tours extends \Elementor\Widget_Base { | |
use Ratings; | |
public function get_name() { | |
return 'travelux_tours'; | |
} | |
public function get_title() { | |
return __('Tours', 'travelux-core'); | |
} | |
public function get_icon() { | |
return 'fa fa-umbrella-beach'; | |
} | |
public function get_categories() { | |
return ['travelux']; | |
} | |
protected function _register_controls() { | |
$this->start_controls_section( | |
'tour_content_section', | |
[ | |
'label' => __('Content', 'travelux-core'), | |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, | |
] | |
); | |
$getTourArgs = array( | |
'post_type' => 'travelux_tour', | |
); | |
$getAllTours = get_posts($getTourArgs); | |
$tourList = array(); | |
foreach ($getAllTours as $item){ | |
$tourList[$item->ID] = $item->post_title; | |
} | |
$this->add_control( | |
'tour_ids', | |
[ | |
'label' => __( 'Select Tour', 'travelux-core' ), | |
'type' => \Elementor\Controls_Manager::TEXT, | |
'multiple' => true, | |
'options' => $tourList, | |
] | |
); | |
$this->end_controls_section(); | |
$this->start_controls_section( | |
'tour_carousel_control_section', | |
[ | |
'label' => __('Slide Controls', 'travelux-core'), | |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, | |
] | |
); | |
$this->add_control( | |
'slide_items', | |
[ | |
'label' => __('Slide Items', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::NUMBER, | |
'min' => 1, | |
'max' => 10, | |
'step' => 1, | |
'default' => 3, | |
] | |
); | |
$this->add_control( | |
'spacing', | |
[ | |
'label' => __('Spacing', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::SLIDER, | |
'size_units' => ['size'], | |
'range' => [ | |
'size' => [ | |
'min' => 20, | |
'max' => 100, | |
'step' => 5, | |
], | |
], | |
'default' => [ | |
'size' => 20, | |
], | |
] | |
); | |
$this->add_control( | |
'hr', | |
[ | |
'type' => \Elementor\Controls_Manager::DIVIDER, | |
'style' => 'thick', | |
] | |
); | |
$this->add_control( | |
'autoplay', | |
[ | |
'label' => __('Autoplay', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::SWITCHER, | |
'label_on' => __('Yes', 'your-plugin'), | |
'label_off' => __('no', 'your-plugin'), | |
'return_value' => 'true', | |
'default' => 'true', | |
] | |
); | |
$this->add_control( | |
'nav', | |
[ | |
'label' => __('Navigation Icon', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::SWITCHER, | |
'label_on' => __('Show', 'your-plugin'), | |
'label_off' => __('Hide', 'your-plugin'), | |
'return_value' => 'true', | |
'default' => 'false', | |
] | |
); | |
$this->add_control( | |
'dots', | |
[ | |
'label' => __('Dots Pagination', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::SWITCHER, | |
'label_on' => __('Show', 'your-plugin'), | |
'label_off' => __('Hide', 'your-plugin'), | |
'return_value' => 'true', | |
'default' => 'true', | |
] | |
); | |
$this->add_control( | |
'loop', | |
[ | |
'label' => __('Loop', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::SWITCHER, | |
'label_on' => __('Yes', 'your-plugin'), | |
'label_off' => __('no', 'your-plugin'), | |
'return_value' => 'true', | |
'default' => 'true', | |
] | |
); | |
$this->add_control( | |
'smartspeed', | |
[ | |
'label' => __('Speed', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::NUMBER, | |
'min' => 50, | |
'min' => 5000, | |
'step' => 0, | |
'default' => 1100, | |
] | |
); | |
$this->add_control( | |
'timeout', | |
[ | |
'label' => __('Timeout', 'seokit-core'), | |
'type' => \Elementor\Controls_Manager::NUMBER, | |
'min' => 500, | |
'min' => 10000, | |
'step' => 50, | |
'default' => 6000, | |
] | |
); | |
$this->end_controls_section(); | |
$this->start_controls_section( | |
'style_section', | |
[ | |
'label' => __( 'Style', 'travelux-core' ), | |
'tab' => \Elementor\Controls_Manager::TAB_STYLE, | |
] | |
); | |
$this->add_group_control( | |
\Elementor\Group_Control_Typography::get_type(), | |
[ | |
'name' => 'title_typography', | |
'label' => __( 'Typography', 'travelux-core' ), | |
'selector' => '{{WRAPPER}} .ft-card .ft-card__content .ft-card__head h4', | |
] | |
); | |
$this->end_controls_section(); | |
} | |
protected function render() { | |
$settings = $this->get_settings_for_display(); | |
$this->add_render_attribute('wrapper', 'id', 'ft-card-carousel-' . uniqid()); | |
$this->add_render_attribute('wrapper', 'class', 'ft-card-carousel owl-carousel owl-theme jsFeaturedTour'); | |
$slider_options = [ | |
'item_count' => $settings['slide_items'], | |
'autoplay' => $settings['autoplay'], | |
'nav' => $settings['nav'], | |
'dots' => $settings['dots'], | |
'loop' => $settings['loop'], | |
'spacing' => $settings['spacing']['size'], | |
'speed' => $settings['smartspeed'], | |
'timeout' => $settings['timeout'], | |
]; | |
$tourArgs = array( | |
'post_type' => 'travelux_tour', | |
'order_by' => 'post__in', | |
'post__in' => explode( ', ', $settings['tour_ids'] ), | |
'ignore_sticky_posts' => 1, | |
); | |
$tours = new WP_Query($tourArgs); | |
if ($tours->have_posts()): ?> | |
<div <?php echo $this->get_render_attribute_string('wrapper'); ?> data-options='<?php echo wp_json_encode($slider_options); ?>'> | |
<?php | |
while ($tours->have_posts()): | |
$tours->the_post(); | |
$destination_name = get_the_terms(get_the_ID(), 'destination'); | |
?> | |
<div id="<?php echo get_the_ID(); ?>" class="ft-card"> | |
<?php | |
if (has_post_thumbnail()): | |
$thumbnail = get_the_post_thumbnail_url(get_the_ID(), 'travelux-tour-slide'); | |
printf('<div class="ft-card__img"><img src="%s" alt="%s"></div>', $thumbnail, get_the_title()); | |
endif; | |
?> | |
<div class="ft-card__content"> | |
<div class="ft-card__head"> | |
<?php $this->display_tour_grid_destination();?> | |
<h4><a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a></h4> | |
<div class="ft-card__rating"> | |
<?php | |
$this->display_tour_grid_star_rating(); | |
$this->display_tour_grid_review_count(); | |
?> | |
</div> | |
</div> | |
<div class="ft-card__bottom"> | |
<?php | |
$this->display_tour_grid_meta_info(); | |
$this->display_tour_grid_carousel_price(); | |
?> | |
</div> | |
<div class="ft-card__details"> | |
<a href="<?php echo get_the_permalink(); ?>" class="btn btn-details btn-block"><?php echo __('View details', 'travelux'); ?></a> | |
</div> | |
</div> | |
</div> | |
<?php endwhile; | |
$tours->reset_postdata(); | |
?> | |
</div> | |
<?php | |
endif; | |
} | |
protected function _content_template() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment