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

(avery) #1

CHAPTER 4 • WordPress Theme Essentials 87






// The content
the_content();
?>

With that established, it’s time to create some more template files!


SINGLE POSTS AND PAGES


Most themes sport both single.php and page.php templates. The former is for single posts,
and the latter is for pages. A simple theme such as the one you’re building now really doesn’t
need these; a few conditional tags could do everything without complicating the index.php
file. But forget about that and create a single.php and page.php template.


Start with single.php, which really doesn’t differ too much from index.php. In fact, it is
basically a simplified index.php, without the fallback stuff and with get_template_part(
'content', 'single' ) instead of the get_post_format() solution mentioned
previously. A single post should look the same no matter what, in this case at least, so
content-single.php will do.


Here’s the complete single.php:


<?php get_header(); ?>




<?php
// Start the loop
while ( have_posts() ) : the_post();


// Get the correct content type
get_template_part( 'content', 'single' );

Free download pdf