Skip to content

Instantly share code, notes, and snippets.

@dasbairagya
Last active January 20, 2017 21:28
Show Gist options
  • Select an option

  • Save dasbairagya/ee4dd8c0bca1c71cd36d55ec6419148e to your computer and use it in GitHub Desktop.

Select an option

Save dasbairagya/ee4dd8c0bca1c71cd36d55ec6419148e to your computer and use it in GitHub Desktop.
Dynamically create active class within loop
<div class="carousel-inner" role="listbox">
<?php
$c = 0;
$class = '';
query_posts('category_name=slider&showposts=3');
if ( have_posts() ) : while ( have_posts() ) : the_post();
$c++;
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
$url = $thumb['0'];
if ( $c == 1 ) $class .= ' active';
?>
<div class="item <?php echo $class; ?>">
<img src="<?php echo $url; ?>" class="img-responsive" alt="...">
<div class="carousel-caption">
<h2><?php the_content() ?></h2>
</div>
</div>
<?php
endwhile;endif;
wp_reset_query();
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment