92 PART II • Designing and Developing WordPress Themes
</header>
<?php
// Start the loop
while ( have_posts() ) : the_post();
// Get the correct content type
get_template_part( 'content', get_post_format() );
// Loop ends
endwhile;
?>
</section> <!-- #main-container ends -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
Basically, this is the index.php template without the fallback stuff, but with a conditional if
else statement at the top outputting various headings for the different situations. This handles
day, month, year, category, and tag archives, along with a general fallback just in case. You
should be pretty comfortable with these template files by now, right?
404, SEARCH, AND SCREENSHOTS
There are additional templates a theme should have. Two very prominent ones are a 404
template, for those cases when a user reaches a URL on your domain that doesn’t exist, and
a search template for displaying search results. Called 404.php and search.php, these two are
pretty straightforward. The following is a simple 404.php file, which really should contain
more help for the user, but you’ll get to that later in the book:
<?php get_header(); ?>
<div id="main-container">
<section id="content-container">
<article id="post-0" class="post no-results not-found">
<header>
<h1 class="entry-title">404 Page Not Found</h2>
</header>
<p>Oops, this page doesn't seem to exist. Maybe the link pointing here
was faulty?</p>
<p>Would you like to search for whatever you were looking for?</p>
<?php get_search_form(); ?>
</article>
</section> <!-- #main-container ends -->