- In order to create the template file itself open a text editor such as Visual Studio Code and paste the following code in the editor in a new, blank file : <?php /* Template Name: Blog Template with Sidebar */ ?> then save the file with the file extension “.php”.
- Upload the newly created template php file to your FTP server in the “/wp-content/themes/Blog Template with Sidebar” folder. If you have a child theme upload the template to that folder instead.
- To check if your created template is working go to Word Press Admin click on Pages then Add New, after that on the right side under Template choose your newly created template from the menu, for example in the dropdown instead of “Default Template” choose “Blog Template with Sidebar”(The name of the template you created)
- To make your newly created template display content use this example:
<?php /* Template Name: Blog Template with Sidebar */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template. ?>
<div class="content">
<div class="title"><?php the_title(); ?></div>
<div class="excerpt"><?php the_excerpt(); ?></div>
</div><?php
// End of the loop.
endwhile; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Leave a Comment