Episode 22 of 32
The Single.php Template
Build the single.php template for individual blog posts — full content, author, date, categories, and post navigation.
The Single.php Template
The single.php template displays a single blog post with its full content, author, date, categories, tags, and navigation to previous/next posts.
Creating single.php
<?php get_header(); ?>
<main id="main-content">
<div class="container">
<div class="content-wrapper">
<div class="primary-content">
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="single-post">
<h1 class="post-title"><?php the_title(); ?></h1>
<div class="post-meta-full">
<span class="date">📅 <?php echo get_the_date(); ?></span>
<span class="author">✍️ <?php the_author(); ?></span>
<span class="category">📁 <?php the_category(', '); ?></span>
</div>
<?php if (has_post_thumbnail()) : ?>
<div class="post-featured-img">
<?php the_post_thumbnail('large'); ?>
</div>
<?php endif; ?>
<div class="post-body">
<?php the_content(); ?>
</div>
<div class="post-tags">
<?php the_tags('<span class="tag-label">Tags: </span>', ', '); ?>
</div>
</article>
<!-- Post Navigation -->
<nav class="post-navigation">
<div class="nav-prev">
<?php previous_post_link('« %link'); ?>
</div>
<div class="nav-next">
<?php next_post_link('%link »'); ?>
</div>
</nav>
<!-- Comments -->
<?php comments_template(); ?>
<?php endwhile;
endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
</main>
<?php get_footer(); ?>
Template Tags Used
| Function | What It Outputs |
|---|---|
the_title() | The post title |
the_content() | The full post content |
get_the_date() | The post date |
the_author() | The post author's display name |
the_category(', ') | Category links, comma-separated |
the_tags() | Tag links with custom prefix |
previous_post_link() | Link to the previous post |
next_post_link() | Link to the next post |
comments_template() | Loads the comments section |
Styling the Single Post
.post-title {
font-size: 34px;
color: #2c3e50;
margin-bottom: 12px;
line-height: 1.3;
}
.post-meta-full {
display: flex;
gap: 20px;
font-size: 14px;
color: #888;
margin-bottom: 24px;
padding-bottom: 16px;
border-bottom: 1px solid #eee;
}
.post-featured-img {
margin-bottom: 24px;
border-radius: 8px;
overflow: hidden;
}
.post-featured-img img {
width: 100%;
height: auto;
}
.post-body {
font-size: 16px;
line-height: 1.9;
color: #444;
}
.post-tags {
margin-top: 30px;
padding-top: 16px;
border-top: 1px solid #eee;
font-size: 14px;
}
.post-navigation {
display: flex;
justify-content: space-between;
padding: 24px 0;
margin-top: 30px;
border-top: 1px solid #eee;
}
.post-navigation a {
color: #3498db;
font-weight: 600;
}
.post-navigation a:hover {
color: #2c3e50;
}
Key Takeaways
single.phpdisplays full blog post content usingthe_content()- Include post metadata (date, author, categories, tags) for context
- Use
previous_post_link()andnext_post_link()for sequential navigation comments_template()loads the built-in WordPress commenting system- Featured images with
the_post_thumbnail('large')provide visual impact