My goal here is to use multiple wordpress loops to style each post in a given category separately. I do believe I have it mostly figured out except for the actual query..
I need to be able to query the {MOST RECENT} post in a category in the first loop, then on the second loop query the 2nd most recent post in a category, then the 3rd most recent post in the next loop, enabling me to have separate classes & styles for each.
Any help would be amazing +++!!
<?php if (have_posts()) : ?>
<?php query_posts('category_name=Main&posts_per_page=1&={MOST RECENT}'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="row1">
<div class="one">
<div class="post_data">
<div class="icons_right"><img src="pop_out_icon.png" alt="pop out icon" /></div>
<h1 class="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<h2 class="post_snippet">Lorem Ipsum Dolar Sit Amet.</h2>
<p class="post_date"><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></p>
</div> <!-- post_data //-->
<?php the_content(); ?>
</div> <!-- 1 //-->
<?php endwhile; ?>
<?php query_posts('category_name=Main&posts_per_page=1&={SECOND MOST RECENT}'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="row2">
<div class="two">
<div class="post_data">
<div class="icons_right"><img src="pop_out_icon.png" alt="pop out icon" /></div>
<h1 class="post_title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<h2 class="post_snippet">Lorem Ipsum Dolar Sit Amet.</h2>
<p class="post_date"><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></p>
</div> <!-- post_data //-->
<?php the_content(); ?>
</div> <!-- 2 //-->
<?php endwhile; ?>
<?php endif; ?>
I notice that although you want to use different loops to define unique classes, your loop blocks are largely the same. If all you want to do is change the classes of your elements, there’s no need to use three separate loops, as that will clutter up your template and end up being much slower than using a single loop.
You should also avoid using query_posts, as it overrides the default WordPress Loop, and may have unintended consequences, especially if you forget to reset the query.
The order of the posts in the loop defaults to the most recent posts, so you don’t need to worry about setting the ordering parameters.
Using your example, I’ve reworked everything to apply dynamic classes to your wrappers depending on how many iterations the loop has gone through. Keep in mind, you can use attributes of the post itself to define your classes to make them unique (in this case, the post ID is used):
UPDATE: Now your top wrapper will store 4 posts per row. This can be adjusted however you need through the $postsPerRow variable, and you can always increase the Posts_per_page parameter as needed.
EDIT 2: Using WP Query has the added benefit of separating out values you might need. Review the code for an update to your latest question.