have_posts() ) return; /* Generate classes for the slider wrapper */ $class = array( 'carousel', 'slide', 'carousel-fade' ); $class[] = $blograzzi_settings['slider_display_style']; $class = apply_filters( 'blograzzi_slider_class', $class ); $class = implode( ' ', $class ); $slidernav_html = ''; $i = 0; do_action( 'blograzzi_before_slider' ); ?>
Previous Next
tag of the the slider image. * * It requires the post's ID to be passed in as argument so that the user settings in * individual post / page can be retrieved. */ function blograzzi_get_slider_image( $post_id = NULL, $size = 'thumbnail', $urlonly = false, $default = '' ){ global $blograzzi_settings; // Throw an error message if no post ID supplied if ( $post_id == NULL){ echo 'ERROR: Post ID must be passed as an input argument to call the function blograzzi_get_slider_image().'; return; } // First get the settings $global_setting = ( $blograzzi_settings['slider_img'] ) ? $blograzzi_settings['slider_img'] : 'featured_image'; $local_setting = blograzzi_get_post_meta( $post_id, 'slider_img' ); $local_setting = ( $local_setting ) ? $local_setting : ''; // Determine which image should be displayed $final_setting = ( $local_setting == '' ) ? $global_setting : $local_setting; // Build the html based on the final setting $html = ''; if ( $final_setting == 'disabled' ){ // image disabled return false; } elseif ( $final_setting == 'featured_image' ){ // Featured Image if ( has_post_thumbnail( $post_id ) ) : if ( $urlonly ) $html = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), $size ); else $html .= get_the_post_thumbnail( $post_id, $size ); endif; } elseif ( $final_setting == 'post_image' ){ // First image in post $html = blograzzi_get_post_image( $post_id, $size, '', $urlonly); } elseif ( $final_setting == 'custom_url' ){ // Custom URL if ( ! $urlonly ){ $html .= ''; if ( $local_setting != '' ) : $html .= ''; else : $html .= ''; endif; } else { if ( $local_setting != '' ) : $html .= esc_url( blograzzi_get_post_meta( $post_id, 'slider_imgurl' ) ); else : $html .= esc_url( $blograzzi_settings['slider_imgurl'] ); endif; } } if ( ! $html ) $html = $default; // Returns the html return $html; } endif; /** * Returns the posts to be displayed in the slider * * @return object Object containing the slider posts * @package Blograzzi * @since 1.6 */ if ( ! function_exists( 'blograzzi_get_slider_posts' ) ) : function blograzzi_get_slider_posts(){ global $blograzzi_settings; /* Get the category whose posts should be displayed here. */ $slidertype = ( $blograzzi_settings['slider_type'] != '' ) ? $blograzzi_settings['slider_type'] : false; /* Set the post types to be displayed */ $slider_post_type = ( in_array( $slidertype, array( 'posts_pages', 'categories' ) ) ) ? array( 'post', 'page' ) : array( 'post' ) ; $slider_post_type = apply_filters( 'blograzzi_slider_post_type', $slider_post_type ); /* Get the number of posts to show */ $postcount = $blograzzi_settings['slider_postcount']; $args = array( 'posts_per_page' => $postcount, 'orderby' => 'menu_order date', 'order' => 'DESC', 'suppress_filters' => 0, 'post_type' => $slider_post_type, 'ignore_sticky_posts' => 1, // otherwise the sticky posts show up undesired ); /* Get the slider content to display */ if ( $slidertype && $slidertype == 'random' ) { $args = array_merge( $args, array( 'orderby' => 'rand' ) ); } if ( $slidertype && $slidertype == 'posts_pages' && $blograzzi_settings['slider_specific_posts'] ) { $post_ids = $blograzzi_settings['slider_specific_posts']; $post_ids = preg_split("/[\s]*[,][\s]*/", $post_ids, -1, PREG_SPLIT_NO_EMPTY); // post_ids are comma separated, the query needs a array $post_ids = blograzzi_object_id( $post_ids ); $args = array_merge( $args, array( 'post__in' => $post_ids, 'posts_per_page' => -1, 'orderby' => 'post__in' ) ); } if ( $slidertype && $slidertype == 'categories' && is_array( $blograzzi_settings['slider_specific_categories'] ) ) { $cats = $blograzzi_settings['slider_specific_categories']; $cats = blograzzi_object_id( $cats, 'category' ); $args = array_merge( $args, array( 'category__in' => $cats ) ); if ( $blograzzi_settings['slider_random_category_posts'] ) $args = array_merge( $args, array( 'orderby' => 'rand' ) ); } /* Get only posts with featured image */ if ( $blograzzi_settings['slider_with_image_only'] ) { $args['meta_query'][] = array( 'key' => '_thumbnail_id', 'compare' => 'EXISTS' ); } if ( isset( $args['meta_query'] ) && count( $args['meta_query'] ) > 1 ) $args['meta_query']['relation'] = 'AND'; /* Get the posts */ $sliderposts = new WP_Query( apply_filters( 'blograzzi_slider_args', $args ) ); return apply_filters( 'blograzzi_slider_posts', $sliderposts ); } endif; /** * Exclude posts that belong to the categories displayed in slider from the posts listing */ function blograzzi_exclude_slider_categories( $request ){ global $blograzzi_settings, $blograzzi_defaults; if ( $blograzzi_settings['slider_type'] != 'categories' ) return $request; if ( is_admin() ) return $request; if ( $blograzzi_settings['slider_exclude_categories'] != $blograzzi_defaults['slider_exclude_categories'] ){ $dummy_query = new WP_Query(); $dummy_query->parse_query( $request ); if ( get_option( 'show_on_front' ) == 'page' && $dummy_query->query_vars['page_id'] == get_option( 'page_on_front' ) ) return $request; if ( ( $blograzzi_settings['slider_exclude_categories'] == 'everywhere' ) || $blograzzi_settings['slider_exclude_categories'] == 'homepage' && $dummy_query->is_home() ) $request['category__not_in'] = blograzzi_object_id( $blograzzi_settings['slider_specific_categories'], 'category' ); } return $request; } add_filter( 'request', 'blograzzi_exclude_slider_categories' );