Disclaimer: The title of this post isn’t a “relationship status” 😉 It is instead a file that WordPress uses to display single posts on the site.
As seen before, the famous WordPress loop can be used in index.php to fetch and display all the posts on the site.
<h1> <?php bloginfo('name'); ?> </h1>
<p> <?php bloginfo('description'); ?> </p>
<?php
while (have_posts()) {
the_post(); ?>
<h2> <?php the_title(); ?> </h2>
<p> <?php the_content(); ?> </p>
<?php
}
?>
This loop gets us the following result on the front page of the site (when our theme is active):

This displays all the posts on the front page but we’d like to have an option to open each one separately.
To do so, let’s modify our code and wrap the title in a tag with href pointing to the_permalink() which fetches the permanent link of the respective post.
<h1> <?php bloginfo('name'); ?> </h1>
<p> <?php bloginfo('description'); ?> </p>
<?php
while (have_posts()) {
the_post(); ?>
<h2> <a href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a></h2>
<p> <?php the_content(); ?> </p>
<?php
}
?>
The result? Each post title becomes a link that allows us to open the post at a unique URL –


Notice that the title is still a link. It doesn’t have to be, especially when we’ve already opened the post.
To fix this, let’s create another file called single.php in our theme’s folder and add the index.php code in there (without the permalink part).
<h1> <?php bloginfo('name'); ?> </h1>
<p> <?php bloginfo('description'); ?> </p>
<?php
while (have_posts()) {
the_post(); ?>
<h2> <?php the_title(); ?> </h2>
<p> <?php the_content(); ?> </p>
<?php
}
?>
Now when we open any post, its title won’t be a link.

What’s happening here? Previously index.php was taking care of all the pages on the site. Now index.php is only taking care of the front page while single.php is taking care of all the web pages that are “posts” on the site.
The same can be done for web pages that are “pages” on the site by using page.php file in the theme’s folder.
This allows us to customise home page, single posts and single pages separately while developing a WordPress theme.