Last active
August 29, 2015 14:04
-
-
Save immanuelsun/772da67cd82922f3b4ad to your computer and use it in GitHub Desktop.
A slideshow using Bootstrap carousel in WordPress.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Featured Post Carousel --> | |
<!-- The Query --> | |
<?php | |
$args = array( | |
'post_type' => 'post', | |
'category_name' => 'featured' | |
); | |
$the_query = new WP_Query( $args ); | |
?> | |
<div id="featured-posts" class="carousel slide" data-ride="carousel"> | |
<!-- Indicators --> | |
<ol class="carousel-indicators"> | |
<!-- Start the Loop --> | |
<?php | |
if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); | |
$the_count = $the_query->current_post; | |
?> | |
<li data-target="#featured-posts" data-slide-to="<?php echo $the_count; ?>" <?php if($the_count == 0): ?>class="active"<?php endif; ?> ></li> | |
<!-- End the Loop --> | |
<?php endwhile; endif; ?> | |
</ol> | |
<?php rewind_posts(); ?> | |
<!-- Wrapper for slides --> | |
<div class="carousel-inner"> | |
<?php | |
if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); | |
$the_count = $the_query->current_post; | |
$attachment_id = get_post_thumbnail_id(get_the_ID()); | |
$attachment_meta = wp_prepare_attachment_for_js( $attachment_id ); | |
$image_url = $attachment_meta['url']; | |
$image_caption = $attachment_meta['caption']; | |
$image_description = $attachment_meta['description']; | |
$image_alt = $attachment_meta['alt']; | |
?> | |
<div class="item <?php echo $the_count; ?> <?php if($the_count == 0): ?>active<?php endif; ?>"> | |
<a href="<?php the_permalink(); ?>"><img class="carousel-image" src="<?php echo $image_url; ?>" alt="<?php echo $image_alt; ?>"></a> | |
<div class="carousel-caption"> | |
<h5><?php the_title(); ?></h5> | |
<p><?php echo $image_description; ?></p> | |
</div> <!--/ carousel-caption --> | |
</div> | |
<!-- End the Loop --> | |
<?php endwhile; endif; ?> | |
</div> <!--/ carousel-inner --> | |
<!-- Controls --> | |
<a class="left carousel-control" href="#featured-posts" role="button" data-slide="prev"> | |
<span class="glyphicon glyphicon-chevron-left"></span> | |
</a> | |
<a class="right carousel-control" href="#featured-posts" role="button" data-slide="next"> | |
<span class="glyphicon glyphicon-chevron-right"></span> | |
</a> | |
</div> <!--/ #featured-posts carousel slide --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment