84 PART II • Designing and Developing WordPress Themes
There’s not much to talk about here, really. There are some checks to see whether the comments
are open, and if they are, they are outputted; otherwise, they are not. The latter comment check
is meant for fallbacks mostly because it will be true only on single posts and pages (that’s what
the conditional tag is_singular() checks for), but it could come in handy should the
theme lack a single.php template for some reason.
Putting it all together, you’ve got this index.php file:
<?php get_header(); ?>
<div id="main-container">
<section id="content-container">
<?php
// Start the loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
// Show the date once per page
the_date( '', '<h3 class="the_date">', '</h3>' );
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" title="<?php
the_title_attribute(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h2>
<p class="entry-meta">
Posted on <time datetime="<?php echo get_the_date(); ?>"><?php
the_time(); ?></time>
by <?php the_author_link(); ?>
<?php
// Are the comments open?
if ( comments_open() ) : ?>
• <?php comments_popup_link( 'No comments', '1 comment', '%
comments' );
endif;
?>
</p>
</header>
<?php
// The content
the_content();
?>
</article>
<?php
// Load comments if singular
if ( is_singular() ) {
comments_template( '', true );
}
// Loop ends
endwhile;