Breaking News
Home / wordpress tutorials / How to create a custom template in wordpress

How to create a custom template in wordpress

Whether you run a blog or a website, having a custom template its a good practice.

Most people love to showcase their best post and coupons instead of showing the latest post on their home page, this is where custom template comes in.

Template are use to display a blog post on any page depending on the customization done on the template.

Using a custom template is useful if you want to add some customization to a blog. for example when using the home page as a forum, storefront, or landing page.

In this post i am going to teach you how to display post in a  custom page with navigation  using  a custom template.

Step 1: Page template

Open any text editor in your computer e.g notepad  or  Dream Wearer if you have it installed in your computer to Create a blank page template named “goldensepak-blog.php” and include the following code below:



Template Name: Blog



<?php get_header(); ?>// use to display your blog descriptions and navigation menu




<?php // Display blog posts on any page

$temp = $wp_query; $wp_query= null;

$wp_query = new WP_Query(); $wp_query->query(‘posts_per_page=5’ . ‘&paged=’.$paged);

while ($wp_query->have_posts()) : $wp_query->the_post(); ?>


<h2><a href=”<?php the_permalink(); ?>” title=”Read more”><?php the_title(); ?></a></h2>

<?php the_excerpt(); ?>


<?php endwhile; ?>


<?php if ($paged > 1) { ?>


<nav id=”nav-posts”>

<div class=”prev”><?php next_posts_link(‘&laquo; Previous Posts’); ?></div>

<div class=”next”><?php previous_posts_link(‘Newer Posts &raquo;’); ?></div>



<?php } else { ?>


<nav id=”nav-posts”>

<div class=”prev”><?php next_posts_link(‘&laquo; Previous Posts’); ?></div>



<?php } ?>


<?php wp_reset_postdata(); ?>




<?php get_footer(); ?>

Note: if you are using notepad, save  the page  with php extension. that is goldenspeak.php.

This template is made to display  5 posts by default, you can set posts_per_page=15  or whatever works best.

Note that the post-navigation is conditional, such that the first page of posts (i.e., your /blog/ page) doesn’t display empty markup/styles for the “next posts” link.

NOTE: this is just Html and Php, you need to add some Css to display the post according to your blog theme design.

Step 2: Add New Page

Once goldenspeak.php is saved and uploaded to the server, log in to the WP Admin  dashboard and visit the Add New Page screen. There, create a new page named “goldenspeak” (or any other name you like to call the new page), and set its Template as “goldenspeak” from the “Page Attributes” panel located at the right side .

page setup

When you click on it, a drop down menu with the list of available template in your theme will be review, just click on the name of the template you just created(goldenspeak).

congratulation you just created your first template.Now visit the Blog page to view the page.


Check Also

how to set featured image in wordpress

featured image hack in wordpress

One feature of wordpress  is the ability to assign a featured image  to each post. …

Leave a Reply

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.