Add viator-collector plugin (Hop On Hop Off front-end reskin)
Consolidate the plugin into the TourWebsite repository (its separate nested git repo has been removed). Includes the full new-design reskin: scoped design stylesheet, SVG icon sprite, rebuilt listing/single/section templates, and homepage hero/FAQ/testimonials shortcodes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4hNL1PSHxXbu94SCenpKj
This commit is contained in:
517
viator-collector/includes/class-vc-sections.php
Normal file
517
viator-collector/includes/class-vc-sections.php
Normal file
@@ -0,0 +1,517 @@
|
||||
<?php
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Front-page section shortcodes — "Hop On Hop Off" design.
|
||||
*
|
||||
* All markup is scoped under a .vc-app wrapper and styled by assets/css/
|
||||
* vc-design.css. Assets are enqueued by VC_Display when a page contains one of
|
||||
* these shortcodes, so nothing loads on pages that don't use them.
|
||||
*/
|
||||
class VC_Sections {
|
||||
|
||||
const HERO = 'viator_hero';
|
||||
const TOP_DESTS = 'viator_top_destinations';
|
||||
const TOP_ATTRS = 'viator_top_attractions';
|
||||
const ACTIVITIES = 'viator_browse_activities';
|
||||
const TOP_TOURS = 'viator_top_tours';
|
||||
const FAQ = 'viator_faq';
|
||||
const REVIEWS = 'viator_testimonials';
|
||||
|
||||
/** Per-request counter so each rail gets a unique id for its nav buttons. */
|
||||
private static $rail_seq = 0;
|
||||
|
||||
public static function init() {
|
||||
add_shortcode( self::HERO, array( __CLASS__, 'hero' ) );
|
||||
add_shortcode( 'viator_hero_slider', array( __CLASS__, 'hero' ) ); // back-compat alias
|
||||
add_shortcode( self::TOP_DESTS, array( __CLASS__, 'top_destinations' ) );
|
||||
add_shortcode( self::TOP_ATTRS, array( __CLASS__, 'top_attractions' ) );
|
||||
add_shortcode( self::ACTIVITIES, array( __CLASS__, 'browse_activities' ) );
|
||||
add_shortcode( self::TOP_TOURS, array( __CLASS__, 'top_tours' ) );
|
||||
add_shortcode( self::FAQ, array( __CLASS__, 'faq' ) );
|
||||
add_shortcode( self::REVIEWS, array( __CLASS__, 'testimonials' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_hero title="Set out on the journey." image="https://…"]
|
||||
*
|
||||
* The booking hero: a location/date/seat form that routes to the tours
|
||||
* archive pre-filtered by the chosen destination.
|
||||
*/
|
||||
public static function hero( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'title' => __( 'Set out on the journey.', 'viator-collector' ),
|
||||
'eyebrow' => __( 'Tour & Travel', 'viator-collector' ),
|
||||
'image' => '',
|
||||
),
|
||||
$atts,
|
||||
self::HERO
|
||||
);
|
||||
|
||||
$img = $atts['image'] ? $atts['image'] : vc_hero_image_url();
|
||||
if ( ! $img ) {
|
||||
$img = vc_asset_url( 'img/hero.png' );
|
||||
}
|
||||
$archive = get_post_type_archive_link( 'viator_tour' );
|
||||
$archive = $archive ? $archive : home_url( '/' );
|
||||
|
||||
$dests = get_terms( array( 'taxonomy' => 'viator_destination', 'hide_empty' => true, 'number' => 12, 'orderby' => 'count', 'order' => 'DESC' ) );
|
||||
$dests = is_wp_error( $dests ) ? array() : $dests;
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="vc-app vc-sections">
|
||||
<section class="hero">
|
||||
<div class="hero__media">
|
||||
<img class="hero__img" src="<?php echo esc_url( $img ); ?>" alt="" fetchpriority="high">
|
||||
<div class="hero__scrim" aria-hidden="true"></div>
|
||||
</div>
|
||||
<div class="container hero__content">
|
||||
<p class="pill hero__eyebrow"><?php echo esc_html( $atts['eyebrow'] ); ?></p>
|
||||
<h1 class="hero__title"><?php echo esc_html( $atts['title'] ); ?></h1>
|
||||
|
||||
<form class="booking" method="get" action="<?php echo esc_url( $archive ); ?>" novalidate>
|
||||
<div class="booking__row">
|
||||
<div class="field">
|
||||
<span class="field__label"><?php echo vc_icon( 'location' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><label for="vc-f-location"><?php echo esc_html__( 'Location', 'viator-collector' ); ?></label></span>
|
||||
<div class="select">
|
||||
<select class="select__input" id="vc-f-location" name="dest[]">
|
||||
<option value=""><?php echo esc_html__( 'All destinations', 'viator-collector' ); ?></option>
|
||||
<?php foreach ( $dests as $t ) : ?>
|
||||
<option value="<?php echo esc_attr( $t->slug ); ?>"><?php echo esc_html( $t->name ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php echo vc_icon( 'chevron', 'select__chevron' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<span class="field__label"><?php echo vc_icon( 'calendar' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><label for="vc-f-date"><?php echo esc_html__( 'Date', 'viator-collector' ); ?></label></span>
|
||||
<div class="select">
|
||||
<input class="select__input select__input--date" id="vc-f-date" name="date" type="text" placeholder="<?php echo esc_attr__( 'Select Date', 'viator-collector' ); ?>" data-datefield>
|
||||
<?php echo vc_icon( 'chevron', 'select__chevron' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<span class="field__label"><?php echo vc_icon( 'seat' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?><label for="vc-f-seat"><?php echo esc_html__( 'Seat', 'viator-collector' ); ?></label></span>
|
||||
<div class="select">
|
||||
<select class="select__input" id="vc-f-seat" name="seat">
|
||||
<option value="1"><?php echo esc_html__( 'One Seat', 'viator-collector' ); ?></option>
|
||||
<option value="2"><?php echo esc_html__( 'Two Seats', 'viator-collector' ); ?></option>
|
||||
<option value="3"><?php echo esc_html__( 'Three Seats', 'viator-collector' ); ?></option>
|
||||
<option value="4"><?php echo esc_html__( 'Four Seats', 'viator-collector' ); ?></option>
|
||||
</select>
|
||||
<?php echo vc_icon( 'chevron', 'select__chevron' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button class="btn btn--dark booking__submit" type="submit"><?php echo esc_html__( 'Book now', 'viator-collector' ); ?></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php echo vc_ring_badge( 'SCROLL DOWN · SCROLL DOWN · ', $archive, 'scroll' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</section>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a titled rail section and return its unique rail id. Caller fills the
|
||||
* <ul> with cards and then calls close_rail().
|
||||
*/
|
||||
private static function open_rail( $title, $lead, $view_all_url, $view_all_text ) {
|
||||
$id = 'vcRail' . ( ++self::$rail_seq );
|
||||
ob_start();
|
||||
?>
|
||||
<div class="vc-app vc-sections">
|
||||
<section class="section">
|
||||
<div class="container">
|
||||
<div class="sec-head">
|
||||
<h2 class="sec-head__title"><?php echo wp_kses( $title, array( 'br' => array() ) ); ?></h2>
|
||||
<?php if ( $lead ) : ?><p class="sec-head__lead"><?php echo esc_html( $lead ); ?></p><?php endif; ?>
|
||||
<div class="sec-head__actions">
|
||||
<?php if ( $view_all_url ) : ?>
|
||||
<a class="btn btn--ghost btn--wide" href="<?php echo esc_url( $view_all_url ); ?>"><span><?php echo esc_html( $view_all_text ); ?></span><?php echo vc_icon( 'arrow-ne' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></a>
|
||||
<?php endif; ?>
|
||||
<div class="rail-nav">
|
||||
<button class="btn btn--ghost rail-nav__btn" type="button" data-rail-prev="<?php echo esc_attr( $id ); ?>" aria-label="<?php echo esc_attr__( 'Previous', 'viator-collector' ); ?>"><?php echo vc_icon( 'arrow-left' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></button>
|
||||
<button class="btn btn--ghost rail-nav__btn" type="button" data-rail-next="<?php echo esc_attr( $id ); ?>" aria-label="<?php echo esc_attr__( 'Next', 'viator-collector' ); ?>"><?php echo vc_icon( 'arrow-right' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="rail rail--dest" id="<?php echo esc_attr( $id ); ?>">
|
||||
<?php
|
||||
return array( 'id' => $id, 'head' => ob_get_clean() );
|
||||
}
|
||||
|
||||
private static function close_rail() {
|
||||
return '</ul></div></section></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_top_tours limit="8" title="Most Liked Tours"]
|
||||
*/
|
||||
public static function top_tours( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'ids' => '',
|
||||
'codes' => '',
|
||||
'destination' => '',
|
||||
'tag' => '',
|
||||
'limit' => 8,
|
||||
'orderby' => 'rating',
|
||||
'title' => __( 'Most Liked<br>Tours', 'viator-collector' ),
|
||||
'lead' => __( 'Hand-picked tours travellers loved most.', 'viator-collector' ),
|
||||
),
|
||||
$atts,
|
||||
self::TOP_TOURS
|
||||
);
|
||||
return self::tour_rail( $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_top_attractions limit="8"]
|
||||
*/
|
||||
public static function top_attractions( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'ids' => '',
|
||||
'codes' => '',
|
||||
'destination' => '',
|
||||
'tag' => '',
|
||||
'limit' => 8,
|
||||
'orderby' => 'rating',
|
||||
'title' => __( 'Top<br>Attractions', 'viator-collector' ),
|
||||
'lead' => __( 'The must-see experiences everyone books.', 'viator-collector' ),
|
||||
),
|
||||
$atts,
|
||||
self::TOP_ATTRS
|
||||
);
|
||||
return self::tour_rail( $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_browse_activities limit="8"]
|
||||
*/
|
||||
public static function browse_activities( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'ids' => '',
|
||||
'codes' => '',
|
||||
'destination' => '',
|
||||
'tag' => '',
|
||||
'limit' => 8,
|
||||
'orderby' => 'rating',
|
||||
'title' => __( 'Browse By<br>Activity', 'viator-collector' ),
|
||||
'lead' => __( 'Find your style — from city sights to river cruises.', 'viator-collector' ),
|
||||
),
|
||||
$atts,
|
||||
self::ACTIVITIES
|
||||
);
|
||||
return self::tour_rail( $atts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared: a rail of tour cards from a curated/filtered query.
|
||||
*/
|
||||
private static function tour_rail( array $atts ) {
|
||||
$query = self::tour_query( $atts );
|
||||
if ( ! $query->have_posts() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$archive = get_post_type_archive_link( 'viator_tour' );
|
||||
$rail = self::open_rail( $atts['title'], $atts['lead'], $archive, __( 'See all', 'viator-collector' ) );
|
||||
|
||||
ob_start();
|
||||
echo $rail['head']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
while ( $query->have_posts() ) {
|
||||
$query->the_post();
|
||||
echo vc_get_template( 'card-tour.php', array( 'post_id' => get_the_ID(), 'variant' => 'rail' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
echo self::close_rail(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
wp_reset_postdata();
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_top_destinations limit="8" title="Where you wanna go?"]
|
||||
*
|
||||
* A rail of destination-term cards; each links to the term archive.
|
||||
*/
|
||||
public static function top_destinations( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'ids' => '',
|
||||
'slugs' => '',
|
||||
'limit' => 8,
|
||||
'orderby' => 'count',
|
||||
'title' => __( 'Where you<br>wanna go?', 'viator-collector' ),
|
||||
'lead' => __( 'Popular destinations our travellers explore.', 'viator-collector' ),
|
||||
'link_text' => __( 'View tours', 'viator-collector' ),
|
||||
),
|
||||
$atts,
|
||||
self::TOP_DESTS
|
||||
);
|
||||
|
||||
$args = array( 'taxonomy' => 'viator_destination', 'hide_empty' => true );
|
||||
if ( '' !== $atts['ids'] ) {
|
||||
$args['include'] = array_filter( array_map( 'absint', explode( ',', $atts['ids'] ) ) );
|
||||
$args['orderby'] = 'include';
|
||||
} elseif ( '' !== $atts['slugs'] ) {
|
||||
$args['slug'] = array_filter( array_map( 'sanitize_title', explode( ',', $atts['slugs'] ) ) );
|
||||
$args['orderby'] = 'name';
|
||||
} else {
|
||||
$args['number'] = max( 1, absint( $atts['limit'] ) );
|
||||
$args['orderby'] = ( 'name' === $atts['orderby'] ) ? 'name' : 'count';
|
||||
$args['order'] = ( 'name' === $atts['orderby'] ) ? 'ASC' : 'DESC';
|
||||
}
|
||||
|
||||
$terms = get_terms( $args );
|
||||
if ( is_wp_error( $terms ) || empty( $terms ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$archive = get_post_type_archive_link( 'viator_tour' );
|
||||
$rail = self::open_rail( $atts['title'], $atts['lead'], $archive, __( 'See all', 'viator-collector' ) );
|
||||
|
||||
ob_start();
|
||||
echo $rail['head']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
foreach ( $terms as $term ) {
|
||||
$link = get_term_link( $term );
|
||||
if ( is_wp_error( $link ) ) {
|
||||
continue;
|
||||
}
|
||||
$image = vc_term_image_url( $term->term_id, 'viator_destination' );
|
||||
?>
|
||||
<li class="dcard">
|
||||
<?php if ( $image ) : ?>
|
||||
<img class="dcard__img" src="<?php echo esc_url( $image ); ?>" alt="<?php echo esc_attr( $term->name ); ?>" loading="lazy">
|
||||
<?php endif; ?>
|
||||
<div class="dcard__body">
|
||||
<h3 class="dcard__title"><a href="<?php echo esc_url( $link ); ?>"><?php echo esc_html( $term->name ); ?></a></h3>
|
||||
<div class="dcard__meta">
|
||||
<div class="meta">
|
||||
<span class="meta__k"><?php echo esc_html__( 'Tours', 'viator-collector' ); ?></span>
|
||||
<span class="meta__v"><?php echo esc_html( number_format_i18n( (int) $term->count ) ); ?></span>
|
||||
</div>
|
||||
<?php echo vc_ring_badge( 'VIEW TOURS · VIEW TOURS · ', $link, 'card' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
echo self::close_rail(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_faq title="FAQ's" items="Question|Answer;;Question 2|Answer 2"]
|
||||
*
|
||||
* Items may also be supplied via the `vc_faq_items` filter.
|
||||
*/
|
||||
public static function faq( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'title' => __( "FAQ's", 'viator-collector' ),
|
||||
'lead' => __( 'Everything you need to know before you book.', 'viator-collector' ),
|
||||
'items' => '',
|
||||
),
|
||||
$atts,
|
||||
self::FAQ
|
||||
);
|
||||
|
||||
$items = array();
|
||||
if ( '' !== $atts['items'] ) {
|
||||
foreach ( explode( ';;', $atts['items'] ) as $pair ) {
|
||||
$parts = array_map( 'trim', explode( '|', $pair, 2 ) );
|
||||
if ( '' !== $parts[0] && isset( $parts[1] ) ) {
|
||||
$items[] = array( 'q' => $parts[0], 'a' => $parts[1] );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( empty( $items ) ) {
|
||||
$items = apply_filters(
|
||||
'vc_faq_items',
|
||||
array(
|
||||
array( 'q' => __( 'Is the booking process fully online?', 'viator-collector' ), 'a' => __( 'Yes — you can browse, choose a date and complete your booking entirely online in a few minutes.', 'viator-collector' ) ),
|
||||
array( 'q' => __( 'How can I book a tour?', 'viator-collector' ), 'a' => __( 'Pick a tour, choose your date and number of seats, then confirm. You will receive your tickets by email.', 'viator-collector' ) ),
|
||||
array( 'q' => __( 'Can I cancel or change my booking?', 'viator-collector' ), 'a' => __( 'Most tours offer free cancellation up to 24 hours before the start time. Check each tour for details.', 'viator-collector' ) ),
|
||||
array( 'q' => __( 'Do I need to print my ticket?', 'viator-collector' ), 'a' => __( 'No — a mobile ticket is accepted for the vast majority of tours.', 'viator-collector' ) ),
|
||||
)
|
||||
);
|
||||
}
|
||||
if ( empty( $items ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="vc-app vc-sections">
|
||||
<section class="faq">
|
||||
<span class="faq__watermark" aria-hidden="true">FAQ</span>
|
||||
<div class="container faq__inner">
|
||||
<div class="faq__intro">
|
||||
<h2 class="faq__title"><?php echo esc_html( $atts['title'] ); ?></h2>
|
||||
<?php if ( $atts['lead'] ) : ?><p class="faq__lead"><?php echo esc_html( $atts['lead'] ); ?></p><?php endif; ?>
|
||||
</div>
|
||||
<div class="accordion" data-accordion>
|
||||
<?php foreach ( $items as $i => $item ) : ?>
|
||||
<div class="acc">
|
||||
<h3>
|
||||
<button class="acc__q" type="button" aria-expanded="<?php echo 0 === $i ? 'true' : 'false'; ?>">
|
||||
<span><?php echo esc_html( $item['q'] ); ?></span>
|
||||
<?php echo vc_icon( 'plus', 'icon--14 acc__plus' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
<?php echo vc_icon( 'minus', 'icon--14 acc__minus' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
||||
</button>
|
||||
</h3>
|
||||
<div class="acc__a"><p><?php echo esc_html( $item['a'] ); ?></p></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [viator_testimonials title="Your Comments"]
|
||||
*
|
||||
* Items may be supplied via the `vc_testimonials` filter
|
||||
* (each: name, role, text, avatar).
|
||||
*/
|
||||
public static function testimonials( $atts ) {
|
||||
$atts = shortcode_atts(
|
||||
array(
|
||||
'title' => __( 'Your Comments', 'viator-collector' ),
|
||||
'lead' => __( 'What travellers say about their tours.', 'viator-collector' ),
|
||||
),
|
||||
$atts,
|
||||
self::REVIEWS
|
||||
);
|
||||
|
||||
$a1 = vc_asset_url( 'img/ellipse-17.png' );
|
||||
$a2 = vc_asset_url( 'img/ellipse-17-2.png' );
|
||||
$items = apply_filters(
|
||||
'vc_testimonials',
|
||||
array(
|
||||
array( 'name' => 'Malika Favre', 'role' => __( 'Paris Tour', 'viator-collector' ), 'text' => __( 'An unforgettable day — the open-top ride and the guide made the whole city feel new. Booking was effortless.', 'viator-collector' ), 'avatar' => $a1, 'size' => 'lg' ),
|
||||
array( 'name' => 'James Carter', 'role' => __( 'London Tour', 'viator-collector' ), 'text' => __( 'Great value and flexible timing. We hopped on and off all day and saw everything on our list.', 'viator-collector' ), 'avatar' => $a2, 'size' => '' ),
|
||||
array( 'name' => 'Sofia Rossi', 'role' => __( 'Sydney Tour', 'viator-collector' ), 'text' => __( 'Smooth from start to finish. Highly recommended.', 'viator-collector' ), 'avatar' => $a1, 'size' => 'sm' ),
|
||||
array( 'name' => 'Liam Nguyen', 'role' => __( 'San Diego Tour', 'viator-collector' ), 'text' => __( 'Friendly crew, comfortable seats and the best views of the coast.', 'viator-collector' ), 'avatar' => $a2, 'size' => '' ),
|
||||
)
|
||||
);
|
||||
if ( empty( $items ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<div class="vc-app vc-sections">
|
||||
<section class="section testimonials">
|
||||
<div class="container">
|
||||
<div class="testimonials__head">
|
||||
<h2 class="testimonials__title"><?php echo esc_html( $atts['title'] ); ?></h2>
|
||||
<?php if ( $atts['lead'] ) : ?><p class="testimonials__lead"><?php echo esc_html( $atts['lead'] ); ?></p><?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="marquee" data-marquee>
|
||||
<div class="marquee__track">
|
||||
<?php foreach ( $items as $item ) : ?>
|
||||
<?php $size = ! empty( $item['size'] ) ? ' quote--' . sanitize_html_class( $item['size'] ) : ''; ?>
|
||||
<figure class="quote<?php echo esc_attr( $size ); ?>">
|
||||
<figcaption class="quote__head">
|
||||
<?php if ( ! empty( $item['avatar'] ) ) : ?>
|
||||
<img class="quote__avatar" src="<?php echo esc_url( $item['avatar'] ); ?>" alt="" loading="lazy">
|
||||
<?php endif; ?>
|
||||
<span><b><?php echo esc_html( $item['name'] ); ?></b><i><?php echo esc_html( $item['role'] ); ?></i></span>
|
||||
</figcaption>
|
||||
<blockquote><?php echo esc_html( $item['text'] ); ?></blockquote>
|
||||
</figure>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared tour query for the landing sections. Supports curation (ids /
|
||||
* product codes) and filtering (destination / tag), with a sane fallback.
|
||||
*/
|
||||
private static function tour_query( array $atts ) {
|
||||
$args = array(
|
||||
'post_type' => 'viator_tour',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => max( 1, absint( $atts['limit'] ) ),
|
||||
'no_found_rows' => true,
|
||||
'ignore_sticky_posts' => true,
|
||||
);
|
||||
|
||||
if ( '' !== $atts['ids'] ) {
|
||||
$args['post__in'] = array_filter( array_map( 'absint', explode( ',', $atts['ids'] ) ) );
|
||||
$args['orderby'] = 'post__in';
|
||||
} elseif ( '' !== $atts['codes'] ) {
|
||||
$args['meta_query'] = array(
|
||||
'vc_product_codes' => array(
|
||||
'key' => '_vc_viator_product_code',
|
||||
'value' => array_filter( array_map( 'sanitize_text_field', explode( ',', $atts['codes'] ) ) ),
|
||||
'compare' => 'IN',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$tax_query = array();
|
||||
if ( '' !== $atts['destination'] ) {
|
||||
$tax_query[] = array( 'taxonomy' => 'viator_destination', 'field' => 'slug', 'terms' => array_map( 'sanitize_title', explode( ',', $atts['destination'] ) ) );
|
||||
}
|
||||
if ( '' !== $atts['tag'] ) {
|
||||
$tax_query[] = array( 'taxonomy' => 'viator_tag', 'field' => 'slug', 'terms' => array_map( 'sanitize_title', explode( ',', $atts['tag'] ) ) );
|
||||
}
|
||||
if ( $tax_query ) {
|
||||
$args['tax_query'] = $tax_query;
|
||||
}
|
||||
|
||||
if ( ! isset( $args['orderby'] ) ) {
|
||||
switch ( $atts['orderby'] ) {
|
||||
case 'price':
|
||||
$args['meta_key'] = '_vc_price_from';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = 'ASC';
|
||||
break;
|
||||
case 'rand':
|
||||
$args['orderby'] = 'rand';
|
||||
break;
|
||||
case 'date':
|
||||
$args['orderby'] = 'date';
|
||||
$args['order'] = 'DESC';
|
||||
break;
|
||||
default:
|
||||
$args['meta_key'] = '_vc_rating';
|
||||
$args['orderby'] = 'meta_value_num';
|
||||
$args['order'] = 'DESC';
|
||||
}
|
||||
}
|
||||
|
||||
$query = new WP_Query( $args );
|
||||
|
||||
// Ordering by a meta key silently drops posts that lack it; fall back to
|
||||
// newest so the section never empties.
|
||||
if ( ! $query->have_posts() && isset( $args['meta_key'] ) ) {
|
||||
unset( $args['meta_key'] );
|
||||
$args['orderby'] = 'date';
|
||||
$args['order'] = 'DESC';
|
||||
$query = new WP_Query( $args );
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user