• Resolved Jim Bouton

    (@piersrueb)


    I wish to display posts in a grid format with css on each post specific to it’s order on the page: first, second, third and so on.

    I can use the code below to style the first post but after that I’m stumped.

    < ?php $firstClass = 'firstpost'; ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Michael

    (@alchymyth)

    try to use a counter variable in the loop:

    principle:

    if (have_posts()) :
    $counter = 1;
       while (have_posts()) :
          the_post();
    $postclass = 'post-nr-' . $counter; // use this as you would use $firstClass
    $counter++;
          the_content();
       endwhile;
    endif;
    Thread Starter Jim Bouton

    (@piersrueb)

    Thanks for your help, i managed it a slightly different way but you put me on the right track.


    <?php if (have_posts()) : $box = 0 ?>
    <?php while ( have_posts() ) : the_post(); ?>
    <?php $box++ ?>
    <div class="box-<?php echo $box; ?>"></div><!--.box-->
    <?php endwhile; ?>
    <?php else : ?>
    <h1>Not Found</h1>
    <?php endif; ?>

    Michael

    (@alchymyth)

    well done –
    if this isi working for you, please mark this thread as ‘resolved’ – some dropdown field here on the right.

    Thread Starter Jim Bouton

    (@piersrueb)

    Thanks again.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Style posts according to their order on the page.’ is closed to new replies.