php - How to add a specific class to the first post in a custom loop in Wordpress -
php - How to add a specific class to the first post in a custom loop in Wordpress -
first post here patient :) i'll seek explain problem clear can, relevant other people might want same problem mine.
i'd obtain two results in wordpress kid theme (based on bootstrap, wordpress bootstrap master 320, precise):
create double construction 2 different loops, first 1 recent x posts (4, precision) , specific formatting, , sec loop remaining posts , specific formatting add specific category first post in first loop leaving other posts untouchedto clear, aim create bootstrap carousel first 4 posts of loop, , style other normal blog.
as now, i've been able create custom loop first 4 posts code:
<div class="carousel-inner"> <?php global $post; // required $args = array('posts_per_page'=>4); $custom_posts = get_posts($args); foreach($custom_posts $post) : setup_postdata($post); ?> <div class="item"> <?php the_post_thumbnail('large'); ?> <div class="carousel-caption"> <?php the_title(); ?> </div> </div> <?php endforeach; ?> </div>
then i'm going create sec loop "offsetting" first 4 posts. there cleaner solution i'm missing, i've used in past, if have advice won't complain.
as regards sec problem, complex one, i've made research , i've found huge amount of different solutions. none of them working, or maybe i'm not adapting them code above in right way (beware, i'm amateur coder , i'm prone errors).
my lastly seek has been one:
<div class="carousel-inner"> <?php global $post; // required $args = array('posts_per_page'=>4); $custom_posts = get_posts($args); $isfirst = true; foreach($custom_posts $post) : setup_postdata($post); ?> <?php echo '<div class="item'; ?> <?php if ( $isfirst = true ) { echo ' active'; } else { echo ''; } ?> <?php echo '">'; ?> <?php $isfirst = false; ?> <?php the_post_thumbnail('large'); ?> <div class="carousel-caption"> ... </div> </div> <?php endforeach; ?> </div>
of course, tried no avail.
can help me here this? i'm avid learner, , understand wtf wrong me! ;)
thanks in advance, guys , girls! :)
claudio
the next line needs utilize comparison operator. assigning true
$isfirst
, instead of checking it's actual value.
if ( $isfirst = true )
should be:
if ( $isfirst == true )
you can read more them in php documentation.
php wordpress twitter-bootstrap loops foreach
Comments
Post a Comment