Inventory_Presser_Shortcode_Slider::content( array $atts )

content


Description Description

Creates the HTML content of the shortcode


Top ↑

Parameters Parameters

$atts

(array) (Required)


Top ↑

Return Return

(string) HTML that renders a vehicle photo flexslider


Top ↑

Source Source

File: includes/shortcode/class-shortcode-inventory-slider.php

	function content( $atts ) {

		// Canvass shortcode attributes
		$atts             = shortcode_atts(
			array(
				'per_page' => 10,
				'captions' => 'true',
				'orderby'  => 'rand',
				'order'    => 'ASC',
			),
			$atts,
			'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 '';
		}

		// Need flexslider for this content
		wp_enqueue_script( 'invp-flexslider' );
		wp_enqueue_style( 'invp-flexslider' );

		$flex_html = '<div class="flexslider flex-native">'
		. '<ul class="slides">';

		foreach ( $inventory_ids as $inventory_id ) {
			$flex_html .= sprintf(
				'<li><a class="flex-link" href="%s">'
				. '<div class="grid-image" style="background-image: url(\'%s\');">'
				. '</div>',
				get_the_permalink( $inventory_id ),
				invp_get_the_photo_url( 'large', $inventory_id )
			);

			if ( $atts['captions'] ) {
				$flex_html .= sprintf(
					'<p class="flex-caption">%s</p>',
					get_the_title( $inventory_id )
				);
			}

			$flex_html .= '</a></li>';
		}

		return $flex_html . '</ul></div>';
	}