'',
'description' => '',
'type' => $graphene_settings['slider_type'],
'post_types' => $graphene_settings['slider_post_types'],
'specific_posts' => $graphene_settings['slider_specific_posts'],
'specific_categories' => $graphene_settings['slider_specific_categories'],
'exclude_categories' => $graphene_settings['slider_exclude_categories'],
'random_category_posts' => $graphene_settings['slider_random_category_posts'],
'exclude_posts' => $graphene_settings['slider_exclude_posts'],
'exclude_posts_cats' => $graphene_settings['slider_exclude_posts_cats'],
'postcount' => $graphene_settings['slider_postcount'],
'with_image_only' => $graphene_settings['slider_with_image_only'],
'img' => $graphene_settings['slider_img'],
'imgurl' => $graphene_settings['slider_imgurl'],
'display' => $graphene_settings['slider_display_style'],
'height' => $graphene_settings['slider_height'],
'height_mobile' => $graphene_settings['slider_height_mobile'],
'speed' => $graphene_settings['slider_speed'],
'position' => $graphene_settings['slider_position'],
'full_width' => $graphene_settings['slider_full_width'],
'slider_as_header' => $graphene_settings['slider_as_header'],
'id' => 'graphene-slider',
'layout' => 'full-stretched'
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
if ( $args['id'] != 'graphene-slider' ) {
$slider_as_header = false;
$full_width = false;
$with_image_only = $graphene_defaults['slider_with_image_only'];
}
if ( $display != 'full-post' ) graphene_set_excerpt_length( 35 );
/* Get the slider posts */
$sliderposts = graphene_get_slider_posts( $args );
if ( ! $sliderposts->have_posts() ) return;
/* Generate classes for the slider wrapper */
$class = array( 'carousel', 'slide', 'carousel-fade' );
$class[] = 'style-' . $display;
$class = apply_filters( 'graphene_slider_class', $class, $args );
$class = implode( ' ', $class );
$slidernav_html = '';
$i = 0;
do_action( 'graphene_before_slider' );
?>
have_posts() ) :
$sliderposts->the_post();
$style = '';
/* Background image*/
if ( $display == 'bgimage-excerpt' || $display == 'banner' ) {
$image = graphene_get_slider_image( get_the_ID(), 'graphene_slider', true );
if ( $image ){
if ( is_array( $image ) ) $image = $image[0];
$style .= 'style="background-image:url(';
$style .= apply_filters( 'jetpack_photon_url', $image );
$style .= ');"';
}
}
/* Link URL */
$slider_link_url = esc_url( graphene_get_post_meta( get_the_ID(), 'slider_url' ) );
if ( ! $slider_link_url ) $slider_link_url = get_permalink();
$slider_link_url = apply_filters( 'graphene_slider_link_url', $slider_link_url, get_the_ID() );
?>
class="item current_post == 0 ) echo 'active'; ?>" id="slider-post-">
post_count > 1 ) : ?>
post_count; $i++ ) : ?>
- data-slide-to="">
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 graphene_get_slider_image( $post_id = NULL, $size = 'thumbnail', $urlonly = false, $default = '' ){
global $graphene_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 graphene_get_slider_image()
.';
return;
}
// First get the settings
$global_setting = ( $graphene_settings['slider_img'] ) ? $graphene_settings['slider_img'] : 'featured_image';
$local_setting = graphene_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 = graphene_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( graphene_get_post_meta( $post_id, 'slider_imgurl' ) );
else :
$html .= esc_url( $graphene_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 Graphene
* @since 1.6
*/
if ( ! function_exists( 'graphene_get_slider_posts' ) ) :
function graphene_get_slider_posts( $args = array() ){
global $graphene_settings;
$defaults = array(
'type' => $graphene_settings['slider_type'],
'post_types' => $graphene_settings['slider_post_types'],
'specific_posts' => $graphene_settings['slider_specific_posts'],
'specific_categories' => $graphene_settings['slider_specific_categories'],
'exclude_categories' => $graphene_settings['slider_exclude_categories'],
'random_category_posts' => $graphene_settings['slider_random_category_posts'],
'exclude_posts' => $graphene_settings['slider_exclude_posts'],
'exclude_posts_cats' => $graphene_settings['slider_exclude_posts_cats'],
'postcount' => $graphene_settings['slider_postcount'],
'with_image_only' => $graphene_settings['slider_with_image_only'],
'img' => $graphene_settings['slider_img'],
'imgurl' => $graphene_settings['slider_imgurl'],
'display' => $graphene_settings['slider_display_style'],
'height' => $graphene_settings['slider_height'],
'height_mobile' => $graphene_settings['slider_height_mobile'],
'speed' => $graphene_settings['slider_speed'],
'position' => $graphene_settings['slider_position'],
'full_width' => $graphene_settings['slider_full_width'],
'slider_as_header' => $graphene_settings['slider_as_header'],
'id' => 'graphene-slider',
);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
/* Set the post types to be displayed */
$slider_post_type = ( in_array( $type, array( 'posts_pages', 'categories' ) ) ) ? array( 'post', 'page' ) : $post_types ;
$slider_post_type = apply_filters( 'graphene_slider_post_type', $slider_post_type );
/* Get the number of posts to show */
$postcount = $graphene_settings['slider_postcount'];
$query_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 ( $type == 'random' ) {
$query_args = array_merge( $query_args, array( 'orderby' => 'rand' ) );
}
if ( $type == 'posts_pages' && $specific_posts ) {
$post_ids = graphene_object_id( explode( ',', $specific_posts ) );
/* Check if any of the ID is excluded */
if ( $exclude_posts ) {
$exclude_post_ids = graphene_object_id( explode( ',', $exclude_posts ) );
foreach ( $post_ids as $i => $post_id ) {
if ( in_array( $post_id, $exclude_post_ids ) ) unset( $post_ids[$i] );
}
}
$query_args = array_merge( $query_args, array( 'post__in' => $post_ids, 'posts_per_page' => -1, 'orderby' => 'post__in' ) );
}
if ( $type == 'categories' && is_array( $specific_categories ) ) {
$specific_categories = graphene_object_id( $specific_categories, 'category' );
$query_args = array_merge( $query_args, array( 'category__in' => $specific_categories ) );
if ( $random_category_posts ) $query_args = array_merge( $query_args, array( 'orderby' => 'rand' ) );
}
/* Exclude posts and pages from slider */
if ( $exclude_posts ) {
$exclude_post_ids = graphene_object_id( explode( ',', $exclude_posts ) );
$query_args = array_merge( $query_args, array( 'post__not_in' => $exclude_post_ids ) );
}
if ( $exclude_posts_cats ) {
$exclude_cats = graphene_object_id( $exclude_posts_cats, 'category' );
$query_args = array_merge( $query_args, array( 'category__not_in' => $exclude_cats ) );
}
/* Get only posts with featured image */
if ( $with_image_only ) {
$query_args['meta_query'][] = array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS'
);
}
if ( isset( $query_args['meta_query'] ) && count( $query_args['meta_query'] ) > 1 ) $query_args['meta_query']['relation'] = 'AND';
// disect_it( $query_args );
/* Get the posts */
$sliderposts = new WP_Query( apply_filters( 'graphene_slider_args', $query_args, $args ) );
return apply_filters( 'graphene_slider_posts', $sliderposts, $query_args, $args );
}
endif;
/**
* Exclude posts that belong to the categories displayed in slider from the posts listing
*/
function graphene_exclude_slider_categories( $request ){
global $graphene_settings, $graphene_in_slider;
if ( $graphene_in_slider ) return $request;
if ( $graphene_settings['slider_type'] != 'categories' ) return $request;
if ( ! $graphene_settings['slider_exclude_categories'] ) return $request;
if ( is_admin() ) return $request;
$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;
$request['category__not_in'] = graphene_object_id( $graphene_settings['slider_specific_categories'], 'category' );
return $request;
}
add_filter( 'request', 'graphene_exclude_slider_categories' );
/**
* Display slider entry meta
* @since Graphene 2.4
*/
function graphene_slider_entry_meta(){
global $graphene_settings, $post;
$post_id = $post->ID;
$meta = array();
/* Date */
$meta['date'] = array(
'class' => 'date',
'meta' => ' ' . get_the_time( get_option( 'date_format' ) )
);
/* Category */
if ( ! $graphene_settings['hide_post_cat'] ) {
$cats = get_the_category(); $categories = array();
if ( $cats ) {
foreach ( $cats as $cat ) $categories[] = '' . $cat->name . '';
}
if ( $categories ) {
$meta['categories'] = array(
'class' => 'categories',
'meta' => ' ' . implode( ', ', $categories )
);
}
}
/* Author */
if ( ! $graphene_settings['hide_post_author'] && $post->post_type == 'post' ) {
$author = '' . get_the_author_meta( 'display_name' , $post->post_author ) . '';
$meta['author'] = array(
'class' => 'post-author',
'meta' => ' ' . $author
);
}
$meta = apply_filters( 'graphene_slider_entry_meta', $meta, $post_id );
if ( ! $meta ) return;
?>