Last active
January 20, 2017 21:28
-
-
Save dasbairagya/ee4dd8c0bca1c71cd36d55ec6419148e to your computer and use it in GitHub Desktop.
Dynamically create active class within loop
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
| <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