/ Published in: PHP
Using this loop variation you can style differently the first and the last post of a loop, or whatever post you like, as lond as you add a new elseif with the number of the post you desire.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $my_query = new WP_Query('cat=10&showposts=4'); ?> <?php $count = 0; ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?> <?php $count++; ?> <?php if ($count == 1) : ?> <div id="featured"> <div class="span-24 last" id="details">HTML Ipsum Presents</div> <!-- end details --> <h2 class="clear"><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2> <p class="clear"><?php the_content('read more...'); ?></p> </div> <hr/> <?php elseif ($count == 4) : ?> <div class="span-8 last"> <h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3> <p class="clear"><?php the_content('read more...'); ?></p> </div> <?php else : ?> <div class="span-8 border"> <h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3> <p class="clear"><?php the_content('read more...'); ?></p> </div> <?php endif; ?> <?php endwhile; ?>