If you’ve ever used WordPress, you know that all of your posts appear on your home page. This is the default behavior for WordPress. You can create content pages for details like an About page or Contact Me page. And if your template supports it, you can even customize a content page with a look and feel that’s different from your default template. But posts are a different animal. Suppose you want to display a specific post type on a page other than your home page. How do you do it?
This is a challenge I set out to solve for myself. I’m in the process of moving my WordPress.com blog to my own self-hosted site. I want the control and customize-ability a self-hosted solution offers. As a facilitator of the Lead Like Jesus servant leadership encounter workshop, I receive 3-weekly devotional messages from the Lead Like Jesus organization that I want to publically post on a page other than my home page. I want to display them on a dedicated devotional page accessible from the main menu. Easy? Yes, if you know how to do it!
Thanks to custom post types, this task is very do-able and quite easy if you have the right guidance. But finding the right guidance on the web has proven to be very difficult. While I found many pages about custom post types, I found very few that give clear directions on how to create and display them. It’s really as simple as 1-2-3. Here are the steps:
- Register the custom post type in WordPress
- Create single-<custom-type>.php
- Create page-<custom-type>.php
Register the Custom Post Type in WordPress
Registering the custom post type in WordPress requires editing your theme’s functions.php file. To do this:
- Select Appearance from the dashboard
- Choose Editor from the Appearance menu
- Select Theme Functions (functions.php) from the right-most column labeled Templates
- Add the following code to the bottom of the functions.php file.
- Click the Update File button
- Refresh your browser. You should now see a menu for the custom post type on the dashboard menu.
I’m not going to detail the parameters for the register_post_type() function. You can learn all you’ve ever wanted to know about the function here at codex.wordpress.org. And of course, unless you want to name your custom post type “leadlikejesus,” modify the code to your liking before updating functions.php.
The single.php file displays your post when you click the view link on the post listing page or the View button on the post editing page.
To create this file, copy the single.php file you’ll find in your template’s main folder to single-.php. is the name of the custom post type you registered in WordPress in Step 1.
The page-<custom-type>.php file is the actual template you will assign to the page you create to display your custom post types. Unlike the single-<custom-type>.php page we created in Step 2, this time you’ll have to create your own page template. In most cases, the template you are using doesn’t have a model from which we can copy a new file. Luckily, the great folks at WordPress.org have provided a great starting example in this article. My customization of the article’s code is illustrated:
Copy this code into your editor and change the “Template Name:” line in the comment block at the top of the file.
The Template Name appears in the Page Attributes Template dropdown when you create your new display page. You also need to search for the following line of code:
$type = 'leadlikejesus';
Change the ‘leadlikejesus’ to the name of the custom post type your want to use. This is the name that you registered in WordPress in Step 1 and the name you’ll use to replace the ‘’ placeholder in Steps 2 and 3.
After you change the Template Name in the comment block and the $type variable, save your file as page-<custom-type>.php in your template’s main folder. As with the file you created in Step 2, is the name of the custom post type you registered with WordPress in Step 1.
If you are satisfied with the look and feel of your template, there’s nothing more to do to this file. If you want to use a different look and feel from the default template, you’re on your own to add the code to this file.
Pulling It All Together
You’re almost done. WordPress has taken care of all the heavy lifting behind the scenes and leaves the creativity to you. All you have left to do now is create a standard page and assign the page-<custom-type> template we created in Step 3 to it. Save it and view the fruit of your labor.
There’s one word of caution with all of this. If the developer of your template releases an update, you will lose these changes if the functions.php file gets overwritten. Make certain you save the code you added to functions.php in a safe place so you can add it back in again in the future if you need to. An alternative is to create your own child template if your template supports it. But that’s another lesson all together.