- WordPress 2.7 Cookbook
- Jean-Baptiste Jung
- 334字
- 2021-04-01 13:55:51
Using page templates in your theme
Even though most of the WordPress themes use a unique page template, our favorite blogging engine allows us to create as many different page templates as we want.
Why always use the same page layout in your blog? Using different page templates will make your blog look a lot more professional.
In this recipe, you'll learn to create and use page templates.
Getting ready
To achieve this recipe, you only need a WordPress theme and a text editor. In the following example, we use the WordPress default theme. If you're using another theme, you'll have to adjust the code a bit to make it fit your theme HTML markup.
How to do it...
Let us start with creating a test page template and learn how to create more page templates in the following recipes.
- On your theme directory, create a new file and name it
testpage.php
. - Open the
testpage.php
file in your favorite text editor and insert the following code in it:<?php /* Template Name: Test Page */ ?> <?php get_header(); ?> <div id="content" class="narrowcolumn"> <h1>My first page template, called <?php the_title(); ?>!</h1> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
- Login to your WordPress Dashboard and go to Write | Page and give your page a title. You don't have to write any text in the body since it won't be displayed by the page template.
- Scroll down until you see a Page template link. Clicking on the link will open a drop-down menu from where you can select the page template to use. Select the new template, Test Page.
.
- Publish the page.
- Visit your page. You will see a basic page with only a title displaying My first page template, called XXX (the name you have given to the page).
Now, you know how easy it is to create and use page templates in your WordPress theme. This example isn't useful at all, therefore, let us see some really interesting uses of page template in the following recipe.
- VR新未來
- PS職場達人煉成記:人人都能學會的Photoshop辦公設計技巧
- 架構之美
- Joomla! 1.5 SEO
- Unity 2D與3D手機游戲開發實戰
- SPSS進階分析與實務
- Unity Game Development Essentials
- Quickstart Apache Axis2
- ASP.NET jQuery Cookbook
- After Effects中文版入門、精通與實戰
- Jetpack Compose:Android全新UI編程
- Backbone.js Cookbook
- 中文版Flash CS6動畫制作(慕課版)
- Photoshop CC2017圖像處理實例教程
- Photoshop 2020實戰從入門到精通(超值版)