• Skip to main content

Victor Font Consulting Group, LLC

Digital Business Strategists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Computers and Internet / Displaying WordPress 3.x Custom Post Types on a Page Other than Home

Displaying WordPress 3.x Custom Post Types on a Page Other than Home

By Victor M. Font Jr.
November 12, 20104 Comments

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:

  1. Register the custom post type in WordPress
  2. Create single-<custom-type>.php
  3. 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 buttondevotional
  • 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.

Create single-<custom-type>.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.

devotional2devotional3

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.

Create page-<custom-type>.php

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.

CPT Page template selection

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.

  • 6shares
  • Facebook0
  • Twitter2
  • Pinterest0
  • LinkedIn2
  • Print
  • SMS2

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Bruno

    February 22, 2011 at 5:14 pm

    Hello Victor, thanks for your tutorial,
    I’m trying to make the page-.php and i copy your code to my php file, i change the $type to my custom register post name, al nice.

    Now a create the page assign the template a just made and when i check my page in the browser the is empty?????

    It seems that the code inside the loop doesn’t return anything.

    any idea?

    Reply
  2. RS

    February 10, 2011 at 11:10 am

    Thanks for this straightforward explanation. My main question about custom post types has been how to query them effectively, and this answers the question simply. The organization of the article is top-notch

    Thanks again.

    Reply
  3. Piet

    November 12, 2010 at 10:35 pm

    nice tutorial, but I think you should have started with the child theme and not mentioning it as a kind of ps in the last paragraph…

    Reply
    • Victor Font

      November 13, 2010 at 2:11 pm

      Child templates have their own issues that lead to different frustration’s on their own. for example, I have some published pages that I haven’t attached to any menu. When I create a child template with only a .cc file, the un-menued pages show up in the menu of the child template. When you go to edit the menu, the pages are clearly not assigned to it, yet they show up in the child. That’s why I didn’t start with the child template.

      Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2022 Victor M. Font Jr.

Return to top of page
Posting....
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.OkNoCookie policy