Create Your Own WordPress Framework From Scratch: Lesson 8 – Building single.php

In this lesson we will build the single.php template. It is very similar to the index.php template. The main difference is that we don’t need to check for a post’s existence. If we can go to the post’s single template then the post definitely exists.

We also need to add the post navigation partial. We will build this out in a future lesson.

Add the following code to single.php

<?php get_header(); ?>

<main class="main-content">
    <div class="content-holder">

    <?php while ( have_posts() ) : the_post(); ?>

        <?php get_template_part( 'content/content', get_post_format() ); ?>

        <?php get_template_part( 'partials/post-nav' ); ?>

        <?php comments_template(); ?>

    <?php endwhile; ?>

    <!-- /#content -->
    <?php get_sidebar(); ?>


<?php get_footer(); ?>

In the next lesson we will add the generic page template.