How To Create A Custom Page Template In WordPress

by  · 156 COMMENTS

This is a follow-on from my article called: How To Make WordPress Look Like a Website, where we walked through changing which page shows up as the home page for your WordPress website. The idea was to make it look more like a web site rather than a blog.

We changed the front page, but were left with the Page title and Sidebar still. So what if we want to completely customize our home page?

WordPress Page Templates are the answer

WordPress provides a clever way to do this called Custom Page Templates. To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme. Usually that looks something like this: “/wp-content/themes/default” where “default” is your theme name.

That’s where you will create your custom page template file. Create a file called “cover_page.php” and add the following code to it:

<?php
/*
Template Name: Cover Page
*/
?>

<?php get_header(); ?>
Here's my cover page!
<?php get_footer(); ?>
 

The Template Name: Cover Page tells WordPress that this will be a custom page template, where Cover Page is the name that will show up in the drop down selector when you create your page.

The other lines in this file simply include the header and footer of your blog. You can add any HTML that you want to display on your page in the middle.

That’s it – now you have a custom page template!

Creating a Page Based on Your Custom Page Template

Now all you need to do is create a new Page in WordPress:

Add Page in WordPress Screenshot

and assign your new custom page template to it:
Assign page template in WordPress
Now you will have a completely blank home page, with only the header and footer for your site. You can add ANY code you want to this page and customize it until your heart is content.

One caveat though – you’ll find that any content you put into the “page” you created in the WordPress editor will not show up here. Since you are overriding the page with a custom page template, you’ll need to add your content to the cover_page.php file that you created in order for it to show up.

Once you have the page looking the way you want it, go into Settings -> Reading in your WordPress Admin panel and set the “Front page displays” settings to look like this:

Selecting a static home page in the WordPress Reading Settings

Now your custom page will be the first thing visitors see when they come to your website!

Here’s a video walkthrough: Creating WordPress Page Templates.

Update: watch this video to see how to create a custom page template that is editable from the visual WordPress editor!

See my WordPress Powered Websites series for more WordPress articles, tips and tricks for small business websites.


'공부 > Wordpress' 카테고리의 다른 글

제작한 플러그인에 설정메뉴 넣기  (0) 2012.08.10
위젯 만들기  (0) 2012.08.10
루프문설명  (0) 2012.08.08
워드프레스 템플릿 기본구조 ㅡ  (0) 2012.08.06
관리자모드에 Custom 플러그인 메뉴 추가하기  (0) 2012.08.06

+ Recent posts