Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function business_field_render_featured_slider( $slider_details = array() ) {
if ( empty( $slider_details ) ) {
return;
}
$featured_slider_transition_effect = business_field_get_option( 'featured_slider_transition_effect' );
$featured_slider_enable_caption = business_field_get_option( 'featured_slider_enable_caption' );
$featured_slider_caption_alignment = business_field_get_option( 'featured_slider_caption_alignment' );
$featured_slider_enable_arrow = business_field_get_option( 'featured_slider_enable_arrow' );
$featured_slider_enable_pager = business_field_get_option( 'featured_slider_enable_pager' );
$featured_slider_enable_autoplay = business_field_get_option( 'featured_slider_enable_autoplay' );
$featured_slider_enable_overlay = business_field_get_option( 'featured_slider_enable_overlay' );
$featured_slider_transition_duration = business_field_get_option( 'featured_slider_transition_duration' );
$featured_slider_transition_delay = business_field_get_option( 'featured_slider_transition_delay' );
// Cycle data.
$slide_data = array(
'fx' => esc_attr( $featured_slider_transition_effect ),
'speed' => esc_attr( $featured_slider_transition_duration ) * 1000,
'pause-on-hover' => 'true',
'loader' => 'true',
'log' => 'false',
'swipe' => 'true',
'auto-height' => 'container',
);
if ( $featured_slider_enable_pager ) {
$slide_data['pager-template'] = '<span class="pager-box"></span>';
}
if ( $featured_slider_enable_autoplay ) {
$slide_data['timeout'] = absint( $featured_slider_transition_delay ) * 1000;
} else {
$slide_data['timeout'] = 0;
}
$slide_data['slides'] = 'article';
$slide_attributes_text = '';
foreach ( $slide_data as $key => $item ) {
$slide_attributes_text .= ' ';
$slide_attributes_text .= ' data-cycle-' . esc_attr( $key );
$slide_attributes_text .= '="' . esc_attr( $item ) . '"';
}
$overlay_class = ( true === $featured_slider_enable_overlay ) ? 'overlay-enabled' : 'overlay-disabled' ;
?>
<div id="featured-slider">
<div class="cycle-slideshow <?php echo esc_attr( $overlay_class ); ?>" id="main-slider" <?php echo $slide_attributes_text; ?>>
<?php if ( $featured_slider_enable_arrow ) : ?>
<div class="cycle-prev"><i class="fa fa-angle-left" aria-hidden="true"></i></div>
<div class="cycle-next"><i class="fa fa-angle-right" aria-hidden="true"></i></div>
<?php endif; ?>
<?php $cnt = 1; ?>
<?php foreach ( $slider_details as $key => $slide ) : ?>
<?php $class_text = ( 1 === $cnt ) ? 'first' : ''; ?>
<?php
$target = '_self';
if ( isset( $slide['new_window'] ) && 1 === $slide['new_window'] && ! empty( $slide['url'] ) ) {
$target = '_blank';
}
$url = 'javascript:void(0);';
if ( ! empty( $slide['url'] ) ) {
$url = esc_url( $slide['url'] );
}
// Fixing title.
$title = htmlspecialchars_decode( $slide['title'] );
$exploded = explode( '<br>', $title );
if ( ! empty( $exploded ) ) {
$first_part = array_shift( $exploded );
$exploded = array_filter( array_map( 'trim', $exploded ) );
$second_part = implode( ' ', $exploded );
$title = $first_part . '<span>' . $second_part . '</span>';
}
$title = htmlspecialchars( $title );
// Buttons stuff.
$buttons_markup = '';
$primary_button_text = ! empty( $slide['primary_button_text'] ) ? $slide['primary_button_text'] : '' ;
$primary_button_url = ! empty( $slide['primary_button_url'] ) ? $slide['primary_button_url'] : '' ;
$secondary_button_text = ! empty( $slide['secondary_button_text'] ) ? $slide['secondary_button_text'] : '' ;
$secondary_button_url = ! empty( $slide['secondary_button_url'] ) ? $slide['secondary_button_url'] : '' ;
if ( ! empty( $primary_button_text ) || ! empty( $secondary_button_text ) ) {
$buttons_markup .= '<div class="slider-buttons">';
if ( ! empty( $primary_button_text ) ) {
$buttons_markup .= '<a href="' . esc_url( $primary_button_url ) . '" class="custom-button slider-button button-primary">' . esc_html( $primary_button_text ) . '</a>';
}
if ( ! empty( $secondary_button_text ) ) {
$buttons_markup .= '<a href="' . esc_url( $secondary_button_url ) . '" class="custom-button slider-button button-secondary">' . esc_html( $secondary_button_text ) . '</a>';
}
$buttons_markup .= '</div>';
}
?>
<article class="<?php echo esc_attr( $class_text ); ?>" data-cycle-title="<?php echo esc_attr( $title ); ?>" data-cycle-url="<?php echo esc_url( $url ); ?>" data-cycle-excerpt="<?php echo esc_attr( $slide['excerpt'] ); ?>" data-cycle-target="<?php echo esc_attr( $target ); ?>" data-cycle-buttons="<?php echo esc_attr( $buttons_markup ); ?>" >
<?php if ( ! empty( $slide['url'] ) ) : ?>
<a href="<?php echo esc_url( $slide['url'] ); ?>" target="<?php echo esc_attr( $target ); ?>" >
<?php endif; ?>
<img src="<?php echo esc_url( $slide['images'][0]); ?>" alt="<?php echo esc_attr( $slide['title'] ); ?>" />
<?php if ( ! empty( $slide['url'] ) ) : ?>
</a>
<?php endif; ?>
<?php if ( $featured_slider_enable_caption ) : ?>
<?php
if ( isset( $slide['caption_alignment'] ) && ! empty( $slide['caption_alignment'] ) ) {
$caption_alignment_class = 'caption-alignment-' . esc_attr( $slide['caption_alignment'] );
} else {
$caption_alignment_class = 'caption-alignment-' . esc_attr( $featured_slider_caption_alignment );
}
?>
<div class="cycle-caption <?php echo esc_attr( $caption_alignment_class ); ?>">
<div class="caption-wrap">
<h3><a href="<?php echo esc_url( $slide['url'] ); ?>"target="_blank"><?php echo esc_attr( $slide['title'] ); ?></a></h3>
<p><?php echo esc_attr( $slide['excerpt'] ); ?></p>
<?php echo wp_kses_post( $buttons_markup ); ?>
</div><!-- .cycle-wrap -->
</div><!-- .cycle-caption -->
<?php endif; ?>
</article>
<?php $cnt++; ?>
<?php endforeach; ?>
<?php if ( $featured_slider_enable_pager ) : ?>
<div class="cycle-pager"></div>
<?php endif; ?>
</div><!-- #main-slider -->
</div><!-- #featured-slider -->
<?php
}
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.