Inventory_Presser_Shortcode_Photo_Slider::content( array $atts )
Creates the HTML content of the shortcode
On This Page
Parameters Parameters
- $atts
-
(array) (Required) Shortcode attributes array.
Return Return
(string) HTML that renders a vehicle photo flexslider
Source Source
File: includes/shortcode/class-shortcode-photo-slider.php
public function content( $atts ) {
$atts = shortcode_atts(
array(
'id' => null,
'include_carousel' => true,
),
$atts,
'invp_photo_slider'
); // Use shortcode_atts_inventory_slider to filter the incoming attributes.
// Parse boolean values to make life easy on users.
$atts['include_carousel'] = filter_var( $atts['include_carousel'], FILTER_VALIDATE_BOOLEAN );
if ( ! wp_style_is( 'flexslider', 'registered' ) ) {
Inventory_Presser_Plugin::include_scripts_and_styles();
}
// Need flexslider for this content.
wp_enqueue_style( 'flexslider' );
wp_enqueue_style( 'invp-flexslider' );
wp_enqueue_script( 'invp-flexslider' );
// Was the post ID passed in as an argument?
if ( ! empty( $atts['id'] ) ) {
$post_id = intval( $atts['id'] );
} else {
$post_id = get_the_ID();
}
$image_url_lists = invp_get_the_photos( array( 'full', 'large', 'thumb' ), $post_id );
ob_start();
?>
<div id="slider-width"></div>
<div id="slider" class="flexslider">
<ul class="slides">
<?php
if ( isset( $image_url_lists['large'] ) ) {
$image_count = count( $image_url_lists['large'] );
for ( $p = 0; $p < $image_count; $p++ ) {
// Inventory Presser versions 8.1.0 and above provide the 'urls'.
if ( isset( $image_url_lists['urls'][ $p ] ) ) {
printf(
'<li><a data-href="%s">%s</a></li>',
esc_url( $image_url_lists['urls'][ $p ] ),
wp_kses_post( $image_url_lists['large'][ $p ] )
);
} else {
printf(
'<li>%s</li>',
wp_kses_post( $image_url_lists['large'][ $p ] )
);
}
}
}
?>
</ul>
</div>
<?php
if ( $atts['include_carousel'] && isset( $image_url_lists['thumb'] ) && count( $image_url_lists['thumb'] ) > 1 ) {
?>
<div id="carousel" class="flexslider no-preview">
<ul class="slides">
<?php
foreach ( $image_url_lists['thumb'] as $image ) {
printf( '<li>%s</li>', wp_kses_post( $image ) );
}
?>
</ul>
</div>
<?php
}
return ob_get_clean();
}
Expand full source codeCollapse full source codeView on Github