• I’m running a query that’s selecting a bunch of posts. I’d like to be able to put a class in the containing div for each post that has an integer that increases with each post in that loop.

    So essentially the classes would be post1, post2, post3, post4, etc. and I could therefore target them with a stylesheet.

    Any thoughts?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Sure. In and around your loop add a few lines:

    <?php if (have_posts()) : ?>
    <?php $i = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $i++; ?>
    <div id="post-<?php the_ID(); ?>" class="post<?php echo $i; ?>">

    That will make your posts have the classes of:

    post1
    post2
    post3
    etc…

    Thread Starter Darfuria

    (@darfuria)

    Ah, clever!

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Count posts in query’ is closed to new replies.