Advertisement
awan101

carousel

Apr 13th, 2016
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.33 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Carousel template
  4.  *
  5.  * @package NewsAnchor
  6.  */
  7.  
  8.     //Scripts
  9.     function newsanchor_carousel_scripts() {
  10.         wp_enqueue_script( 'newsanchor-owl-script', get_template_directory_uri() .  '/js/owl.carousel.min.js', array( 'jquery' ), true );          
  11.     }
  12.     add_action( 'wp_enqueue_scripts', 'newsanchor_carousel_scripts' );
  13.  
  14.     //Template
  15.     if ( ! function_exists( 'newsanchor_carousel' ) ) {
  16.         function newsanchor_carousel() {
  17.             if ( ( get_theme_mod('carousel_display_front', '1') && is_front_page() ) || ( get_theme_mod('carousel_display_archives', '1') && ( is_home() || is_archive() ) ) || ( ( get_theme_mod('carousel_display_singular') && is_singular() ) ) ) {
  18.  
  19.                 //Get the user choices
  20.                 $number     = get_theme_mod('carousel_number');
  21.                 $cat        = get_theme_mod('carousel_cat');
  22.                 $speed      = get_theme_mod('carousel_speed');
  23.                 $number     = ( ! empty( $number ) ) ? intval( $number ) : 6;
  24.                 $cat        = ( ! empty( $cat ) ) ? intval( $cat ) : '';
  25.                 $speed      = ( ! empty( $speed ) ) ? absint( $speed ) : '4000';
  26.  
  27.                 $cats = get_categories();
  28.                 if(count($cats)){ ?>
  29.                 <div class="roll-posts-carousel col-md-12" data-items="3" data-auto="true" data-speed="<?php echo absint($speed); ?>">
  30.                     <div class="owl-carousel">
  31.                 <?php
  32.                 foreach($cats as $cat):
  33.                    
  34.                     $args = array(
  35.                         'posts_per_page'        => $number,
  36.                         'post_status'           => 'publish',
  37.                         'cat'                   => $cat->term_id,
  38.                         'ignore_sticky_posts'   => true        
  39.                     );
  40.                     $query = new WP_Query( $args );
  41.                     if ( $query->have_posts() ) {
  42.                     ?>
  43.                             <?php while ( $query->have_posts() ) : $query->the_post(); ?>
  44.                                         <div class="item">
  45.                                         <?php if ( has_post_thumbnail() ) : ?>
  46.                                             <?php the_post_thumbnail('newsanchor-carousel-thumb'); ?>
  47.                                         <?php else : ?>
  48.                                             <?php echo '<img src="' . get_stylesheet_directory_uri() . '/images/placeholder.png"/>'; ?>
  49.                                         <?php endif; ?>
  50.                                             <div class="text-over">
  51.                                             <?php the_title( sprintf( '<h4 class="carousel-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h4>' ); ?>
  52.                                         </div>
  53.                                         </div>
  54.                             <?php endwhile; ?>
  55.  
  56.                     <?php }
  57.                 endforeach; ?>
  58.                     </div>
  59.                 </div>
  60.                 <?php
  61.                 }
  62.                 wp_reset_postdata();
  63.             }
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement