I have a page with three excerpts. Only the first excerpt is being given the post class, not the second or third. I presume something is wrong in my PHP:
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="100%" valign="top">
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<p><?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?> | <?php the_category(', '); ?> |
<?php comments_number('No comment', '1 comment', '% comments'); ?></p>
</div>
<?php endwhile; else: ?>
<h2>Oops...</h2>
<p>Sorry, no posts we're found.</p>
<?php endif; ?>
<p align="center"><?php posts_nav_link(); ?></p>
</td>
</tr>
</table>
Here is the resulting HTML:
<table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
<tr>
<td width="100%" valign="top">
<div id="post-19" class="post-19 post type-post status-publish format-standard hentry category-printables">
<h2>
<a href="myurl"></a>
</h2>
<p></p>
<p></p>
</div>
<h2></h2>
<p></p>
<p></p>
<h2></h2>
<p></p>
<p></p>
<p align="center"></p>
</td>
</tr>
</tbody>
How do I ensure that the post class is applied to every single excerpt, not just the first one?
while
andendwhile
gets repeated for each post, that's the loop. the thing you want repeated is outside that loop.