Creating Single.php WordPress Post Layout
In this article, we are creating single.php WordPress post layout. This article will demonstrate you how to specify post layout for the WordPress post. So in this tutorial, we will show you how to set the template file of WordPress theme and make them more attractive. we will also learn why we want to use the single.php file in our WordPress theme.
In the previous video, we look out how we will build the WordPress website step by step. But in this article, we will look out post layout which is most important.
This one really one of the simple post layout of WordPress.
Sometimes you want to select different look for your website. The single.php file will do the same thing for you it will give you a way to customize the post. Yes, you heard it right. The single.php file will use to customize your WordPress theme post as per your customization.
So when you change the single.php file it will not affect on index.php file. the single.php file is only affect to the post of the WordPress themes. if you want to change the layout of the post or if you want to change the font family, color, or anything that you do not want to apply to index.php file.
You can create the template file for customizing your post.
So first create Single.php file.
Make sure do not place this file inside of any folder. This is the WordPress template file so if you change the name of the file or change the path of this file WordPress will not recognize this file as the template.
So keep in mind that keep this file in the WordPress theme hierarchy.
After you create Single.php file just put index.php file code inside of it.
So we will put that first.
Template Name: daily
<?php get_header(); ?>
<div class="col-sm-8 p-3">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<p class="post-info"><?php the_time('F j, Y g'); ?>| by <a href="<?php
get_author_posts_url(get_the_author_meta('ID')); ?>"><?php the_author(); ?></a></p>
<p><?php the_content(); ?></p>
<h5><?php echo "No Content Found"; ?></h5>
<?php endif; ?>
<div class="col-sm-4 p-3">
<?php dynamic_sidebar('sidebar_1'); ?>
<?php get_footer(); ?>
In the previous article, we had created this index.php file.
So here we just put all the code from the index.php file and paste it inside of single.php file.
Only the difference has we created a simple div with post-class which creates single border outside of the post.
In the .col-sm-8 class you will see this code
and then create a style for it.
border:1px solid rgb(232,232,232);
In above code, we also wrap the sidebar and apply the border and padding to the sidebar also.
If you run your project nothing will change.
Because you did not change anything. To see changes just change or remove something from single.php file.
You will see the result when you on the home page nothing will change and if you go to the single post your previous changes will affect the single post type.
That’s all for this article see you in the next one.