Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function travel_log_front_page_slider_content() {
$defaults = travel_log_default_values();
$enabled = travel_log_get_theme_option( 'home_slider_enable' );
if ( false === $enabled ) {
return;
}
$slider_category = travel_log_get_theme_option( 'home_slider_category' );
$slider_content_type = travel_log_get_theme_option( 'slider_content_type' );
if ( class_exists( 'WP_Travel' ) ) :
if ( 'trip-types' === $slider_content_type ) :
$slider_category = travel_log_get_theme_option( 'home_slider_category_trip_type' );
elseif ( 'trip-location' === $slider_content_type ) :
$slider_category = travel_log_get_theme_option( 'home_slider_category_trip_location' );
endif;
endif;
$read_more_button_text = travel_log_get_theme_option( 'home_slider_read_more_text' );
if ( class_exists( 'WP_Travel' ) ) {
if ( 'trip-types' === $slider_content_type ) {
if ( empty( $slider_category ) ) {
// get all terms in the taxonomy
$terms = get_terms( 'itinerary_types' );
// convert array of term objects to array of term IDs
$slider_category = wp_list_pluck( $terms, 'term_id' );
}
$args = array(
'post_type' => travel_log_wp_travel_support_get_post_type(),
'tax_query' => array(
array(
'taxonomy' => 'itinerary_types',
'field' => 'id',
'terms' => $slider_category,
),
),
);
} elseif ( 'trip-location' === $slider_content_type ) {
if ( empty( $slider_category ) ) {
// get all terms in the taxonomy
$terms = get_terms( 'travel_locations' );
// convert array of term objects to array of term IDs
$slider_category = wp_list_pluck( $terms, 'term_id' );
}
$args = array(
'post_type' => travel_log_wp_travel_support_get_post_type(),
'tax_query' => array(
array(
'taxonomy' => 'travel_locations',
'field' => 'id',
'terms' => $slider_category,
),
),
);
} else {
$args['category_name'] = $slider_category;
}
} else {
$args['category_name'] = $slider_category;
}
$args['posts_per_page'] = apply_filters( 'travel_log_slider_posts_limit', 5 );
$slider_posts = new WP_Query( $args );
if ( $slider_posts->have_posts() ) :
?>
<div id="featured-slider" class="featured-slider clearfix">
<div class="travel-banner slider">
<?php
while ( $slider_posts->have_posts() ) :
$slider_posts->the_post();
?>
<div>
<div class="slider-image-wrapper">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail( apply_filters( 'travel_log_slider_thumbnail_size', 'full' ) );
else :
travel_log_no_slider_thumbnail();
endif;
?>
<div class="featured-slider-contents">
<h1><?php the_title(); ?></h1>
<p><?php the_excerpt(); ?></p>
<?php
if ( class_exists( 'WP_Travel' ) && 'category' !== $slider_content_type ) : ?>
<i><?php esc_html_e( 'from', 'travel-log' ); ?></i>
<?php wp_travel_trip_price( get_the_ID(), true ); ?>
<?php endif;
?>
<div class="slider-buttons">
<?php if ( ! empty( $read_more_button_text ) ) : ?>
<a href="YOUR LINK" class="slider-info"><?php echo esc_html( $read_more_button_text ); ?></a>
<?php endif; ?>
<?php echo travel_slider_additional_button(); ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_postdata();
?>
</div>
</div>
<?php
endif;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.