/** * Handle ajax requests for the carousel. */ function vantage_carousel_ajax_handler() { if (empty($_GET['query'])) { return; } $query = $_GET['query']; $query['paged'] = $_GET['paged']; $query['post_status'] = 'publish'; $query = new WP_Query($query); ob_start(); ?> <div class="vantage-carousel-wrapper"> <?php $vars = vantage_get_query_variables(); ?> <ul class="vantage-carousel" data-query="<?php echo esc_attr(json_encode($vars)); ?> " data-ajax-url="<?php echo esc_url(admin_url('admin-ajax.php')); ?> "> <?php while ($query->have_posts()) { $query->the_post(); ?> <li class="carousel-entry"> <div class="thumbnail"> <?php if (has_post_thumbnail()) { $img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'vantage-carousel'); ?> <a href="<?php the_permalink(); ?> " style="background-image: url(<?php echo esc_url($img[0]); ?> )"> <span class="overlay"></span> </a> <?php } else { ?> <a href="<?php the_permalink(); ?> " class="default-thumbnail"><span class="overlay"></span></a> <?php } ?> </div> <?php $title = get_the_title(); if (empty($title)) { $title = _e('Post ', 'vantage') . get_the_ID(); } ?> <h3><a href="<?php the_permalink(); ?> "><?php echo $title; ?> </a></h3> </li> <?php } ?> </ul> </div> <?php // Reset everything wp_reset_postdata(); header('content-type:application/json'); echo json_encode(array('html' => ob_get_clean(), 'count' => $query->post_count)); exit; }
<?php /** * Loop Name: Carousel Slider */ ?> <div class="vantage-carousel-wrapper"> <?php $vars = vantage_get_query_variables(); ?> <ul class="vantage-carousel" data-query="<?php echo esc_attr(json_encode($vars)); ?> " data-ajax-url="<?php echo esc_url(admin_url('admin-ajax.php')); ?> "> <?php while (have_posts()) { the_post(); ?> <li class="carousel-entry"> <div class="thumbnail"> <?php if (has_post_thumbnail()) { $img = wp_get_attachment_image_src(get_post_thumbnail_id(), 'vantage-carousel'); ?> <a href="<?php the_permalink();