/** * The geodirectory listing slider shortcode. * * This implements the functionality of the shortcode for displaying listing slider. * * @since 1.0.0 * @package GeoDirectory * @param array $atts { * Attributes of the shortcode. * * @type string $animation Controls the animation type, "fade" or "slide". Default. slide. * @type int $animation_loop Gives the slider a seamless infinite loop. Default. 0. * @type int $animation_speed Set the speed of animations, in milliseconds. Default. 600. * @type string $category Filter by term. Can be any valid term. Default. 0. * @type int $direction_nav Enable previous/next arrow navigation?. Can be 1 or 0. Default. 0. * @type string $order_by Order by filter. Default. latest. * @type string $post_number Number of listings to display. Default. 5. * @type string $post_type Post type of listing. Default. gd_place. * @type string $show_featured_only Do you want to display only featured losting? Can be 1 or 0. Default. Empty. * @type string $show_title Do you want to display title? Can be 1 or 0. Default. Empty. * @type string $slideshow Setup a slideshow for the slider to animate automatically. Default. 0. * @type int $slideshow_speed Set the speed of the slideshow cycling, in milliseconds. Default. 5000. * @type string $title Slider title. Default. Empty. * * } * @return string Slider HTML. */ function geodir_sc_listing_slider($atts) { ob_start(); $defaults = array('post_type' => 'gd_place', 'category' => '0', 'post_number' => '5', 'slideshow' => '0', 'animation_loop' => 0, 'direction_nav' => 0, 'slideshow_speed' => 5000, 'animation_speed' => 600, 'animation' => 'slide', 'order_by' => 'latest', 'show_title' => '', 'show_featured_only' => '', 'title' => ''); $params = shortcode_atts($defaults, $atts); /* * * Now we begin the validation of the attributes. */ // Check we have a valid post_type if (!gdsc_is_post_type_valid($params['post_type'])) { $params['post_type'] = 'gd_place'; } // Check we have a valid sort_order $params['order_by'] = gdsc_validate_sort_choice($params['order_by']); // Match the chosen animation to our options $animation_list = array('slide', 'fade'); if (!in_array($params['animation'], $animation_list)) { $params['animation'] = 'slide'; } // Post_number needs to be a positive integer $params['post_number'] = absint($params['post_number']); if (0 == $params['post_number']) { $params['post_number'] = 1; } // Manage the entered categories if (0 != $params['category'] || '' != $params['category']) { $params['category'] = gdsc_manage_category_choice($params['post_type'], $params['category']); } // Convert show_title to a bool $params['show_title'] = intval(gdsc_to_bool_val($params['show_title'])); // Convert show_featured_only to a bool $params['show_featured_only'] = intval(gdsc_to_bool_val($params['show_featured_only'])); /* * Hopefully all attributes are now valid, and safe to pass forward */ // redeclare vars after validation if (isset($params['direction_nav'])) { $params['directionNav'] = $params['direction_nav']; } if (isset($params['animation_loop'])) { $params['animationLoop'] = $params['animation_loop']; } if (isset($params['slideshow_speed'])) { $params['slideshowSpeed'] = $params['slideshow_speed']; } if (isset($params['animation_speed'])) { $params['animationSpeed'] = $params['animation_speed']; } if (isset($params['order_by'])) { $params['list_sort'] = $params['order_by']; } $query_args = array('post_number' => $params['post_number'], 'is_geodir_loop' => true, 'post_type' => $params['post_type'], 'order_by' => $params['order_by']); if (1 == $params['show_featured_only']) { $query_args['show_featured_only'] = 1; } if (0 != $params['category'] && '' != $params['category']) { $category_taxonomy = geodir_get_taxonomies($params['post_type']); $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $params['category']); $query_args['tax_query'] = array($tax_query); } $defaults = array('before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => ''); $query_args = array_merge($query_args, $params); geodir_listing_slider_widget_output($defaults, $query_args); $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Front-end display content for listing slider widget. * * @since 1.0.0 * @since 1.5.1 Declare function public. * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { geodir_listing_slider_widget_output($args, $instance); }