• About
  • Write For Us
  • Contact
  • Top 50 Photography Blogs
  • Resources
  • Forum

IndustryDev

  • Design
    • Photoshop
    • Lightroom
    • Camera Raw
    • Bridge
  • Development
    • HTML
    • CSS
    • Javascript
    • PHP
    • Dev Tools
    • WordPress
  • Photography
  • Blogging
  • Technology
  • Inspiration
You are here: Home / Wordpress / WordPress Custom Post Type Templates

WordPress Custom Post Type Templates

May 6, 2015

WordPress Custom Post Type Templates

In this post, I’m going to talk about custom post types in WordPress – a very handy bit of knowledge to become familiar with. If you’ve ever wanted to add a custom section of your WordPress website, this post will benefit you. And the thing is, while setting up custom posts and custom archive pages is kind of confusing to begin with, it’s really easy to get the hang of. Once you understand the parts, the challenging areas of this section of your site will be a thing of the past.

Custom Post Type UI

Let’s start off with the primary plugin you’ll need to connect the dots of your custom posts and archive pages. The plugin is called, “Custom Post Type UI” and you can download it here from the WordPress plugin directory and install it manually or you can simply search for it from your plugin area of your WordPress install. Either way, once it’s installed, there are only a few settings you need to be aware of (to get the ball rolling).

After you get the plugin installed, you should see a menu over to the left that looks like this (click for larger image):

CPT-UI Menu

There are a few areas of the setup that need attention. If you click the “Add/Edit Post Types” link in the menu I just described above, you’ll see some fields that need to be filled in.

First, fill in the post type slug. This has the capability of being part of the URL that holds the posts and archive page, so be short, but descriptive. Also, be sure to follow the directions while creating the slug. There are a few rules to follow (example: gallery).

Second, fill in the plural label. This is going to be used as a menu item in the WordPress admin area, so again, keep it short, but descriptive (example: Galleries).

Third, fill in the singular label, which will be used as a heading while you are creating and editing your custom posts. (example: Gallery Section).

Add New Post Type


Next, there are some more advanced areas that need to be set over to the right. In previous versions of this plugin, these were held below the initial settings and were accessed via a link. In the most recent version, all you have to do is click the arrow to the right of the word, “Settings.”

The first attribute you need to set is the “Has Archive” setting. If you set this to true, WordPress will create a custom archive page, specifically for your custom posts. So, if you are creating some sort of a gallery or portfolio with many custom posts, the custom posts can show on a custom archive page. This is probably the most commonly desired option. Also, you have the option of creating a custom slug for the archive page. If you leave this blank, the post type slug will be used.

It’s important to remember that if you do request that an archive be used, either the archive.php or the archives-$posttype.php template file will be used.

The other attribute that needs attention is called, “Rewrite.” This is coupled with “Custom Rewrite Slug.” If you set Rewrite to true, WordPress will “rewrite” your URL path to work with your custom posts. With the Custom Rewrite Slug, you can set this URL to look like whatever you want.

Settings


After all of these areas are set, you should be able to create a new custom post by using the menu to the left in the WordPress admin. So, let’s say you created a label called, “Gallery,” you could mouse over the Gallery link on the left and click the “Add Gallery Section” link. This will bring you to the add post page. Once you add a custom post, you should see the automatically generated slug.

Let’s say, for example, you create a custom post called, “My First Work of Art” and saved it. You should see the slug as “http://www.example.com/gallery/my-first-work-of-art/. If you copy just the beginning part of the slug, for example, http://www.example.com/gallery/, and paste it into a browser, you will see the archive page that holds the custom posts.

In order to add a link to the custom archive page, you’ll need to visit the “Appearance > Menus” section, where you can set up a new “Custom Link.” Once you create the link, add it to the menu you’d like to see it in on your site.

Again, if you don’t have a custom archive page set up specifically for this area of your site, WordPress will use the standard archive.php template for it. If you wanted to create a custom archive page for the, for example, Gallery section, you’d have to create a template file named, archive-gallery.php.

In order for you to have your custom posts listed on a page, such as the archive page, you don’t necessarily need to follow the latter instructions above. You can just as easily not turn on the “Has Archive” setting and go ahead and create a custom page, like I described in an earlier post. If you have a custom page template set up, while creating your custom page in the admin, you would choose the specific page from the “Template” drop down in the “Page Attributes” box. Also, inside the code of the custom page template, you’d add some code to the loop that looks like this:

<?php 
    $args = array(
        'post_type' => 'gallery'
    );
    $the_query = new WP_Query( $args );		    
?>

This would call the custom posts in this category to this custom page.

Finally, we’re going to talk about how to set up an actual custom post template to use with your custom post types. After all, you most likely want these posts to be unique from other posts on your site.

If you look at the WP Hierarchy, under Singular Page > Single Post Page > Custom Post, you’ll see that you have the ability to create a custom post template for these pages. The naming convention for these custom post templates looks like this: single-$posttype.php. If you don’t create this file, the generic fallback single.php will be used. In your custom post template, you can add whatever code you’d like.

I hope I helped you create your custom post types on your website. If you have any questions or comments, please leave them in the comment section below.

Related posts:

  1. Creating WordPress Custom Post Type Templates
  2. Setting Up a WordPress Theme
  3. WordPress Page & Post Templates
  4. Which Is Better For WordPress – Full Post or Summary (Excerpt)?
  5. Working With WordPress Templates

Filed Under: Wordpress

What’s Next? Email Updates!

If you enjoyed reading this post, why not consider signing up to receive others like it by email? It's so easy and you can unsubscribe at any time.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Connect With Me

  • Facebook
  • Instagram
  • Pinterest
  • RSS
  • Twitter

MOST POPULAR POSTS

  • How to Set the Photo Quality in your Canon Rebel DSLR Camera Before participating in any type of photo shoot, it's i...
  • How to Adjust the Mouse Click & Scroll Settings in Windows 10 I's say this is one of the very first settings I ed...
  • How to Export Video From Adobe Photoshop When it comes to exporting and rendering video clips, t...
  • How to Apply an Adjustment to Only One Layer in Adobe Photoshop The answer is clipping. I'll tell you that right up fro...
  • How to Speed Up & Slow Down Video in Adobe Photoshop This is one of those posts that's going to be super hel...
  • Cutting Out a Shape From a Shape in Adobe Photoshop I've been using shapes for various things in Adobe Phot...
  • How to Set the Self Timer On Your Canon Rebel DSLR Camera Camera self timers are great. I was recently part of a...
  • Animating Scale, Rotation & Opacity in Adobe Photoshop I sat down a few days ago and started messing around in...
  • How to Set Your Canon Rebel Camera For Continuous Shooting Continuous Shooting mode is very important for those wh...
  • 3 Ways to Close Applications in Windows 10 This is going to be a very quick post because the topic...

Recent Comments

  • angelica blanco on How to Organize Video & Audio Project Files for Adobe Photoshop
  • pete salomone on Downloading Photos From a Digital Camera Using Adobe Bridge
  • cdn on How To Create a Slideshow For Your Lock Screen in Windows 10
  • Jay Gaulard on How to Set Your Canon Rebel Camera For Continuous Shooting
  • Deb on How to Set Your Canon Rebel Camera For Continuous Shooting

Copyright © 2021 · IndustryDev.com Web Design & Photography Blog · About · Write For Us · Contact · Privacy / Terms · Sitemap