Created
January 5, 2017 14:42
-
-
Save yaulaannl/a317d307bf3eb2cb26c9fefc490c0757 to your computer and use it in GitHub Desktop.
This file contains 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
<?php if(!empty( $featured_posts )): ?> | |
<?php $carousel_id ="featuredCarousel"; ?> | |
<div class="cat-carousel-wrapper"> | |
<div class="my-carousel-1"> | |
<div class="carousel-header"> | |
<h2>Featured Posts</h2> | |
</div> | |
<div id="<?php echo $carousel_id; ?>" class="carousel slide" data-ride="carousel"> | |
<!-- Indicators --> | |
<ol class="carousel-indicators"> | |
<?php | |
for($i = 0; $i < count($featured_posts); $i++){ | |
echo sprintf('<li data-target="#%s" data-slide-to="%d"',$carousel_id,$i); | |
//first one add active class | |
if($i == 0) echo ' class="active"'; | |
echo '></li>'; | |
} | |
?> | |
</ol> | |
<!-- main carousel content --> | |
<div class="carousel-inner" role="listbox"> | |
<?php | |
for($i = 0; $i < count($featured_posts); $i++){ | |
$this_post = $featured_posts[$i]; | |
$am_active = ($i == 0? 'active' : '' ); | |
$img_src = esc_url(get_the_post_thumbnail_url($this_post)); | |
$link_src = esc_url(get_permalink($this_post)); | |
//item wrapper | |
echo sprintf('<div class="item %s">',$am_active); | |
//link spanner | |
echo sprintf('<a href="%s" target="_blank"><span class="link-spanner"></span></a>',$link_src); | |
//image | |
echo sprintf('<img class="carousel-img" src="%s">',$img_src); | |
//content | |
echo '<div class="container">'; | |
echo '<div class="carousel-caption">'; | |
//title | |
echo sprintf('<h4 class="carousel-title">%s</h4>',esc_html($this_post->post_title)); | |
echo '</div>'; | |
echo '</div>'; | |
echo '</div>'; | |
} | |
?> | |
</div><!-- main carousel content --> | |
<!-- left control --> | |
<a class="left carousel-control" href="#<?php echo $carousel_id; ?>" role="button" data-slide="prev"> | |
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> | |
<span class="sr-only">Previous</span> | |
</a> | |
<!-- right control --> | |
<a class="right carousel-control" href="#<?php echo $carousel_id; ?>" role="button" data-slide="next"> | |
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div><!-- featuredCarousel --> | |
</div><!-- my-carousel-1 --> | |
</div><!-- cat-carousel-wrapper --> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment