Skip to content

Instantly share code, notes, and snippets.

Created September 8, 2017 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c418a6629d90766cfcc381e41b0687fc to your computer and use it in GitHub Desktop.
Save anonymous/c418a6629d90766cfcc381e41b0687fc to your computer and use it in GitHub Desktop.
function business_hub_main_slider(){
$theme_options = business_hub_theme_options();
$readmore = $theme_options['read_more_enable'];
$read_more = $theme_options['readmore_text'];
$slider_excerpt = $theme_options['slider_excerpt_enable'];
$slider_number = $theme_options['slider_number'];
if( 'slider' === $theme_options['main_slider_type'] && ( 1 === $theme_options['slider_enable']) ){
if(!empty( $theme_options['slider_cat'] )){
$slider_args = array(
'cat' => absint( $theme_options['slider_cat'] ),
'post_status' => 'publish',
'posts_per_page' => absint( $slider_number),
);
} else{
$slider_args = array( 'post_status' => 'publish', 'posts_per_page' => 5 );
}
$slider_query = new WP_Query( $slider_args );
if ( $slider_query->have_posts() ) : ?>
<div id="main-slider">
<div class="owl-carousel">
<?php
while ( $slider_query->have_posts() ) : $slider_query->the_post();
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); ?>
<div class="item slider-linked" data-target="<?php the_permalink(); ?>" style="background-image: url(<?php echo esc_url($image_url[0]); ?>); ">
<div class="caption">
<h2><?php the_title(); ?></h2>
<?php if( 1 == $slider_excerpt ){ ?>
<div class="entry-content">
<p><?php echo esc_html( business_hub_limit_words( get_the_excerpt(), 25 ) ); ?> </p>
</div>
<?php } ?>
<?php if( 1 == $readmore ){ ?>
<div class="btn btn-business"><a href="<?php the_permalink(); ?>"><?php echo esc_html( $read_more ); ?> <i class="fa fa-angle-right"></i></a></div>
<?php } ?>
</div><!-- .caption -->
</div>
<?php endwhile; ?>
</div>
<div class="scroll-down-wrapper">
<div class="scroll-down">
<a href="#<?php echo esc_html( 'scroll' ); ?>">
<div class="scroll-down-middle"> </div>
<span class="fa fa-angle-double-down"></span>
</a>
</div><!-- .scroll-down -->
</div><!-- .scroll-down-wrapper -->
</div>
<?php wp_reset_postdata();
endif; ?>
<?php } elseif( ( 1 === $theme_options['slider_enable']) ){ ?>
<div id="main-slider" class="main-banner">
<?php
$banner_img = $theme_options['banner_image'];
if( !empty( $banner_img )){
$banner_img_args = array(
'p' => absint( $banner_img ),
'post_status' => 'publish'
);
$banner_img_query = new WP_Query( $banner_img_args );
if ( $banner_img_query->have_posts() ) :
while ( $banner_img_query->have_posts() ) : $banner_img_query->the_post();
$banner_img_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); ?>
<div class="item" style="background-image: url(<?php echo esc_url($banner_img_url[0]); ?>); ">
<div class="caption">
<h2><?php the_title(); ?></h2>
<?php if( 1 == $slider_excerpt ){ ?>
<div class="entry-content">
<p><?php echo esc_html( business_hub_limit_words( get_the_excerpt(), 25 ) ); ?> </p>
</div>
<?php } ?>
<?php if( 1 == $readmore ){ ?>
<div class="btn btn-business"><a href="<?php the_permalink(); ?>"><?php echo esc_html( $read_more ); ?> <i class="fa fa-angle-right"></i></a></div>
<?php } ?>
</div><!-- .caption -->
<div class="scroll-down-wrapper">
<div class="scroll-down">
<a href="#<?php echo esc_html( 'scroll' ); ?>">
<div class="scroll-down-middle"> </div>
<span class="fa fa-angle-double-down"></span>
</a>
</div><!-- .scroll-down -->
</div><!-- .scroll-down-wrapper -->
</div><!-- .item -->
<?php
endwhile;
wp_reset_postdata();
endif;
}
?>
</div><!-- .main-slider -->
<?php }
}
add_action('wp_head', 'business_hub_child_custom_script' );
/**
* [business_hub_child_custom_script Add custom script for slider image click]
* @return [NULL] [description]
*/
function business_hub_child_custom_script(){
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.slider-linked').click(function(){
var link = $(this).attr('data-target');
window.location.href = link;
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment