I've never written PHP before, so I'm having a hard time figuring this out:
I have written an index page that displays posts from new to old in a certain layout. I want the newest post to be stretched across the content area - (class "size1of1") and older posts are two halves of the content area (two smaller, beside each other - class "size1of2"). The last post in a line has the "lastUnit" class - odd numbered posts will have it (including number 1, and the last post, whether even or odd), along with the closing /div (has the class of "line")that contains them.
The problem is, for some reason the else logic isn't getting triggered. The loop goes through for the number of posts for the page, but the else logic never gets done - it's like it is skipping the IF block after the first go.
here is the code for my loop (Sorry, HTML included, so it can be understood):
<?php
$p_loop_count = 1;
$p_post_count = $wp_query->post_count;
if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php if ($p_loop_count == 1) { /* FIRST post */?>
<div class="line">
<div class="unit size1of1 lastUnit thumbnote">
<p>
<strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong><br />
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link(); ?></small>
</p>
<?php the_excerpt(); ?>
<p>
<small>category: <?php the_category(' ') ?></small><br />
<small>tags: <?php the_tags('', ' ', ''); ?></small><br />
<small><?php edit_post_link('edit', '', ' | '); ?> <?php comments_popup_link('no comments »', '1 comment »', '% comments »'); ?></small>
</p>
</div>
</div>
<?php } else { /* Is NOT the first post */ ?>
<?php if ($p_loop_count % 2) { /* odd */?>
<div class="unit size1of2 lastUnit thumbnote">
<p>
<strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong><br />
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link(); ?></small>
</p>
<?php the_excerpt(); ?>
<p>
<small>category: <?php the_category(' ') ?></small><br />
<small>tags: <?php the_tags('', ' ', ''); ?></small><br />
<small><?php edit_post_link('edit', '', ' | '); ?> <?php comments_popup_link('no comments »', '1 comment »', '% comments »'); ?></small>
</p>
</div>
</div>
<?php } ?>
<?php if (!$p_loop_count % 2) { /* even */?>
<?php if ($p_loop_count == $p_post_count) { /* the last post */?>
<div class="line">
<div class="unit size1of2 lastUnit thumbnote">
<p>
<strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong><br />
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link(); ?></small>
</p>
<?php the_excerpt(); ?>
<p>
<small>category: <?php the_category(' ') ?></small><br />
<small>tags: <?php the_tags('', ' ', ''); ?></small><br />
<small><?php edit_post_link('edit', '', ' | '); ?> <?php comments_popup_link('no comments »', '1 comment »', '% comments »'); ?></small>
</p>
</div>
</div>
<?php } else { /* NOT the last post */?>
<div class="line">
<div class="unit size1of2 thumbnote">
<p>
<strong><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></strong><br />
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link(); ?></small>
</p>
<?php the_excerpt(); ?>
<p>
<small>category: <?php the_category(' ') ?></small><br />
<small>tags: <?php the_tags('', ' ', ''); ?></small><br />
<small><?php edit_post_link('edit', '', ' | '); ?> <?php comments_popup_link('no comments »', '1 comment »', '% comments »'); ?></small>
</p>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
<?php $p_loop_count++;
endwhile; ?>
<div class="line">
<div id="post-nav" class="unit size1of1 lastUnit aligncenter">
<?php next_posts_link('« Older Entries') ?> <?php previous_posts_link('Newer Entries »') ?>
</div>
</div>
<?php else : ?>
<h2 class="aligncenter">Not Found</h2>
<p class="aligncenter">Sorry, but you are looking for something that isn't here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
Any help would be appreciated.