I’m building a WordPress theme using the 960 grid system. I’ve got a startpage that displays three thumbnails on each row. These thumbnails are in a child grid with parent wrapper.
So, I need to wrap the first post of each row with a class called “alpha” and the last post (third in my case) of each row with a class called “omega”.
Any idea how I might solve this?
Here’s my current code, any help is appreciated!
<?php get_header(); ?>
<div class="grid_12 projects"><!-- PROJECTS BEGINS -->
<?php
if (have_posts()) :
while (have_posts()) :
?>
<div class="grid_4 project">
<?php
the_post();
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<h2>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h2>
</div><!-- PROJECT ENDS -->
<?php
endwhile;
endif;
?>
</div><!-- PROJECT-CONTAINER ENDS -->
<?php get_footer(); ?>
Note: if you don’t want the last element to always have omega but only if it’s truly the 3rd element on a row, remove
||$ix==$wp_query->post_count
below.Another, and possibly better solution if you are okay with using CSS3 is the nth-child selector.
Ok try this one:
See
//Add this
commentsFull Code: