WordPress how to make a single post template the post details page

the single.php file is use to display as single post default template soto show a single we need to learn wordpress single post template development the single.php file

Single Post

Single Post

the development process of single.php file is similar as page.php file development and the only deference is getting the comment template now will will start to develop step by step.

Step 1.

Create a single.php file inside your theme folder

Step 2.

Take a html design to display the post and copy the html and paste on the single.php file

Step 3.

Now place the header, footer and sidebar of your theme by using the code <?php get_header(); ?>, <?php get_footer(); ?> and <?php get_sidebar(); ?>

Step 5.

Now fetch the all content of the post to be display. use the code <?php if(have_posts()): the_post(); endif; ?> and the comment template for the page bu using the code <?php comments_template(); ?>

Step 6.

now get the title, content and featured image by using the code <?php the_title(); ?>, <?php the_content(); ?> and <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>" class="img-responsive" />

Now the full code for make a single.php file inside your theme folder

<?php get_header(); ?>
<div class="container">
<?php if(have_posts()): the_posts(); ?>
<div class="row">
<div class="col-md-8">
<h2><?php the_title(); ?></h2>
<img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID)); ?>" class="img-responsive" />
<?php the_content(); ?>

<?php comments_template(); ?>
</div>
<div class="col-md-4">
<?php get_sidebar(); ?>
</div>
</div>
<?php endif; ?>
</div>
<?php get_footer(); ?>

Now we have created a default single post template successfully

Thanks for  Reading

Share The Post On -

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.