Thord Daniel Hedengren - Smashing WordPress_ Beyond the Blog-Wiley (2014)

(avery) #1

86 PART II • Designing and Developing WordPress Themes


in the Gallery post format, the code will look for content-gallery.php first — and should that
not exist, it’ll default to content.php. The purpose of this is obviously to be able to reuse
content.php files for various post formats wherever you want.

The following is the complete new 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();
// Get the correct content type
get_template_part( 'content', get_post_format() );

// Load comments if singular
if ( is_singular() ) {
comments_template( '', true );
}
// Loop ends
endwhile;

// Nothing in the loop?
else :
?>
<article id="post-0" class="post no-results not-found">
<header>
<h2 class="entry-title">Nothing Found</h2>
</header>
<p>We're sorry, but we couldn't find anything for you. Please try and
search for whatever it was you were looking for.</p>
<?php get_search_form(); ?>
</article>
<?php
// We're done
endif;
?>
</section> <!-- #main-container ends -->
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

For the record, here are the contents of the content.php file as well:

<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(); ?>
Free download pdf