Jump to content

Add style class for every 3rd div


phensta

Recommended Posts

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

:)

Link to comment
https://forums.phpfreaks.com/topic/241562-add-style-class-for-every-3rd-div/
Share on other sites

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;?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.