phensta Posted July 10, 2011 Share Posted July 10, 2011 Hi, I wander if someone can help me? I need to add 'last' to every 3rd div, but not sure how to go about it. I know I can use something like this: <?php if(($i%3)==0 && $i<>0){ post_class("last");} else {post_class("");} ?>> But I'm not sure how to add it to my script without getting errors. THIS IS MY CODE /////////////////////////// <?php query_posts('showposts=3&cat=20&orderby=rand'); ?> <?php while (have_posts()) : the_post(); ?> <div class="homeBox"> <div class="boxgrid caption"> <a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?> <div class="cover boxcaption"> <h2><?php the_title();?></h2> </div> </a> </div> </div> <?php endwhile;?> //////////////////////////// If someone could help, that would be great. thanks Quote Link to comment https://forums.phpfreaks.com/topic/241562-add-style-class-for-every-3rd-div/ Share on other sites More sharing options...
joel24 Posted July 10, 2011 Share Posted July 10, 2011 this will add the class to the <div class='homebox'> div... <?php query_posts('showposts=3&cat=20&orderby=rand'); $i = 0; while (have_posts()) : the_post(); $i++; $class = ($i%3==0 && $i<>0)? "last" : ""; ?> <div class="homeBox <?php echo $class; ?>"> <div class="boxgrid caption"> <a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?> <div class="cover boxcaption"> <h2><?php the_title();?></h2> </div> </a> </div> </div> <?php endwhile;?> Quote Link to comment https://forums.phpfreaks.com/topic/241562-add-style-class-for-every-3rd-div/#findComment-1240773 Share on other sites More sharing options...
phensta Posted July 11, 2011 Author Share Posted July 11, 2011 yep, that worked a treat! Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/241562-add-style-class-for-every-3rd-div/#findComment-1241154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.