• Skip to main content
  • Skip to primary sidebar

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

  • 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

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

November 12, 2010 By Victor M. Font Jr.

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

Filed Under: Computers and Internet, How To, Programming, WordPress Tagged With: How To, PHP, WordPress

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.

Primary Sidebar

Shopping Cart

Books

  • Ultimate Guide to the SDLC front cover The Ultimate Guide to the SDLC
    Rated 5.00 out of 5
    $74.95
  • Winning With WordPress Basics 2nd Edition Winning With WordPress Basics 2nd Edition $19.95

Recent Articles

  • Modern Scam Defense: How Consumers and Businesses Can Recognize and Stop Email, Phone, and Text Fraud
  • How to Write a PRD So Dense It’s Technically a Novel
  • Top 5 Plugin Names That Scare Our Legal Department
  • When Agile Meets Our 3-Year Waterfall Roadmap: A Love Story
  • Why Our Enterprise Needs 27 Stakeholders to Approve a Button Color Change

Top 10 Article Categories

Best Practice Code Snippet Computers and Internet Genesis How To Leadership Programming Servant Leadership Tutorial WordPress

 
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.