Skip to content

Instantly share code, notes, and snippets.

Created October 18, 2017 04:55
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/86d28290284d5386b71fcf3bb6a502cd to your computer and use it in GitHub Desktop.
Save anonymous/86d28290284d5386b71fcf3bb6a502cd to your computer and use it in GitHub Desktop.
function blog_lite_main_slider(){
$theme_options = blog_lite_theme_options();
$readmore = $theme_options['read_more_enable'];
$date = $theme_options['date_enable'];
if( 'slider' == $theme_options['main_slider_type'] ){
if(!empty( $theme_options['slider_cat'] )){
$slider_args = array( 'cat' => $theme_options['slider_cat'], 'post_status' => 'publish', 'posts_per_page' => 10 );
} else{
$slider_args = array( 'post_status' => 'publish', 'posts_per_page' => 10 );
}
$slider_query = new WP_Query( $slider_args );
if ( $slider_query->have_posts() ) : ?>
<div id="main-slider" class="owl-carousel">
<?php while ( $slider_query->have_posts() ) : $slider_query->the_post(); ?>
<?php $image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' ); ?>
<div class="item" style="background-image: url(<?php echo esc_url($image_url[0]); ?>); ">
<div class="caption v-center">
<h2><?php the_title(); ?></h2>
<?php if( 1 == $date ){ ?>
<div class="entry-meta date"><?php echo esc_html( get_the_date( 'F d, Y' ) ) ; ?></div>
<?php } ?>
<?php if( 1 == $readmore ){ ?>
<div class="readmore"><a href="<?php the_permalink(); ?>"><?php _e('Read More', 'blog-lite');?></a></div>
<?php } ?>
</div><!-- .caption -->
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.', 'blog-lite' ); ?></p>
<?php endif; ?>
<?php } else{ ?>
<div id="main-slider" class="main-banner">
<?php
$banner_img = $theme_options['banner_image'];
$banner_style = '';
if( $banner_img ){
$banner_style = 'style="background-image: url('.esc_url($banner_img).');"';
} ?>
<div class="item" <?php echo $banner_style; ?>>
<div class="caption v-center">
<?php
$banner_title = $theme_options['banner_title'];
if( $banner_title ){ ?>
<h2><?php echo esc_attr( $banner_title ); ?></h2>
<?php } ?>
<?php if( 1 == $date && !empty( $theme_options['banner_sub_title'] )){ ?>
<div class="entry-meta date"><?php echo esc_attr( $theme_options['banner_sub_title'] ); ?></div>
<?php } ?>
<?php if( 1 == $readmore && !empty( $theme_options['banner_link'] ) ){ ?>
<div class="readmore">
<a href="<?php echo esc_url( $theme_options['banner_link'] ); ?>"><?php _e('Read more', 'blog-lite');?></a>
</div>
<?php } ?>
</div><!-- .caption -->
</div><!-- .item -->
</div><!-- .main-slider -->
<?php }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment