Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add class/id into the wordpress loop, but if I add into the loop, it will have the same class/id of each output of posts from the loop.

I know there are conditional statements to add inside the loop to give the first posts or other posts inside the loop the different class/id. But, I don't know how to do that.

For example: I want to give Box 3, Box 6, Box 9, Box 12, Box 15, and a specific boxs a different class/id from others. Please, see the picture.

This is the link of Image: http:// i49.tinypic.com/1s137c.png

Thanks!

Regards!


I want my out put from the loop look like this: http://pastebin.com/BVkje234

And here is my my code I need to use: http://pastebin.com/7DNVWAC3

I want, Box 3, Box 6, Box 9, Box 12, Box 15 to have the <div class='box-last'>

And Box 1 - Box 15, except above boxs to have <div class='box'>

I use normal loop, and I just want to give the last box of each row to have different class/id from the first two box of the row. Thanks!

share|improve this question

closed as too localized by toscho Oct 1 '12 at 22:00

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

2 Answers

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
//Post content
</article>

Is this what you had in mind? or is it something like a sequential numbering?

$cntr = 1;
$posts = get_posts('blahblahblah');
foreach($posts as $post) :
setup_postdata($post);?>
    <li class="<?php echo "post-" . $cntr; ?>">
        //Post Content
    </li>
<?php $cntr++; ?>
<?php endforeach; ?>
share|improve this answer

for more details, please post your existing code and explain how you are going to define 'and a specific boxs'.

assuming your post div uses post_class() and you are using the 'standard' loop: in the post div, re-code the post_class(); code, for example:

<?php post_class( ($wp_query->current_post%3 == 2?'different':'') ); ?> 

edited answer - the div with the css class could look like this:

<div class="<?php echo ( ($wp_query->current_post%3 == 2)?'box-last':'box' ); ?>"> 
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.