Inventory_Presser_Shortcode_Slider::content( array $atts )
Creates the HTML content of the shortcode
On This Page
Parameters Parameters
- $atts
-
(array) (Required)
Return Return
(string) HTML that renders a vehicle photo flexslider
Source Source
File: includes/shortcode/class-shortcode-inventory-slider.php
public function content( $atts ) {
$atts = shortcode_atts(
array(
'captions' => 'true',
'make' => '',
'model' => '',
'orderby' => 'rand',
'order' => 'ASC',
'showcount' => 3, // How many vehicles are shown at one time?
),
$atts,
'invp_inventory_slider'
); // Use shortcode_atts_inventory_slider to filter the incoming attributes.
// Parse boolean values to make life easy on users.
$atts['captions'] = filter_var( $atts['captions'], FILTER_VALIDATE_BOOLEAN );
// Get the vehicle IDs and loop over them.
$inventory_ids = self::get_vehicle_IDs( $atts );
if ( empty( $inventory_ids ) ) {
return '';
}
if ( ! wp_script_is( 'invp-slider', 'registered' ) ) {
Inventory_Presser_Plugin::include_scripts_and_styles();
}
// Need flexslider for this content.
wp_enqueue_style( 'flexslider' );
wp_enqueue_style( 'invp-flexslider' );
wp_enqueue_style( 'invp-slider' );
// Provide one of the widget settings to JavaScript.
wp_add_inline_script(
'invp-slider',
'const widget_slider = ' . wp_json_encode(
array(
'showcount' => $atts['showcount'],
)
),
'before'
);
wp_enqueue_script( 'invp-slider' );
$flex_html = '<div class="widget__invp_slick"><div id="slider-width"></div><div id="widget_slider" class="flexslider flex-native">'
. '<ul class="slides">';
foreach ( $inventory_ids as $inventory_id ) {
$flex_html .= sprintf(
'<li><a class="flex-link" href="%s">'
. '%s',
esc_url( get_the_permalink( $inventory_id ) ),
get_the_post_thumbnail( $inventory_id, 'large' )
);
if ( $atts['captions'] ) {
$flex_html .= sprintf(
'<p class="flex-caption">%s</p>',
esc_html( get_the_title( $inventory_id ) )
);
}
$flex_html .= '</a></li>';
}
return $flex_html . '</ul></div></div>';
}
Expand full source codeCollapse full source codeView on Github