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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.