Grab Your Free 17-Point WordPress Pre-Launch PDF Checklist: wplearninglab.com/17-point-wp...
Custom Post Type Template - Create One To To Customize Designs • Custom Post Type Templ...
Grab your free 17-Point WordPress Pre-Launch PDF Checklist: vid.io/xqRL
Download your exclusive 10-Point WP Security Checklist: bit.ly/10point-wordpress-harde...
What is a WordPress custom post type template?
To answer that, let’s first start with the two post types built into WordPress: posts and pages. Posts are for blog posts and usually display on the front end along with a publication date, an author, comment count, and tags and categories. Pages on the other hand, display without any of that extra information. How post and pages display on the front end is the post type template. A custom post type template then is similar to posts and pages in that it displays content in the front end, but you as the creator of the custom post type can define what information the post editor collects and how it’s displayed on the front end for your visitors. This will make more sense as you go through this tutorial.
All of the extra information that WordPress posts display is called post metadata.
Creating custom post types templates is a two-step process.
Create the custom post type in WordPress (with or without a plugin)
Create the page template that displays the custom post type content to visitors
This tutorial will show you step 2, how to assign a template to the custom post type that displays when that post type is viewed by a visitor.
You will need to complete step 1 before you can do this tutorial. If you need to do step 1, here’s a video tutorial for creating a custom post type without a plugin. For those of you who prefer plugins, here’s a video tutorial for creating a custom post type by using a plugin.
When you’ve completed one of those two tutorials come back to this tutorial and learn how to assign a specific WordPress custom post type template to the custom post type.
Find The Custom Post Type Name
The process starts in the dashboard.
We need to find the name of our custom post type. For instance, I have a custom post type named Products in the left-side admin menu.
When I click on the Products custom post type and the URL will change to this:
wp-phd.com/wp-admin/edit.php?post_type=wpll_product
Yours will look similar.
The post_type is a URL parameter and wpll_product is the value of that parameter. The value is what we need for creating our WordPress custom post type template.
Here are some visual examples for clarity. The value for this example is wpll_product.
The value for this example is music.
Once you know the name of the custom post type, go to your hosting cPanel and open the file manager.
Inside the file manager navigate to wp-content, then themes, then find your active theme, and open it.
In my example, I’m using a child theme. In the child theme folder I don’t have the template files for pages or posts. The default WordPress template file for pages is always pages.php and for posts is always single.php.
Because I don’t want to work with a blank canvas, I’m going to the parent theme folder and copy the single.php file into my child theme ( • How To Duplicate Files... .
To do that go into the parent theme folder, find the single.php file and right click on it. In the context menu that appears click on copy.
In the dialog box that opens enter the path to the child theme folder and click copy file(s).
Now, go back to the child theme folder.
Find the single.php that you just copied there and right-click on it. From the context menu that appears click rename.
The name of the single.php has to be single-*name of your custom post type*.php. In the first case, the name is wpll_product. So the file name for this example would be:
single-wpll_product.php
Now any page that is created in the Product custom post type will use this template to display its’ content. This might seem a little confusing at first, this video on the WordPress hierarchy ( • How The WordPress Hier... ) should help you wrap your head around how WordPress loads files.
Read the rest on the blog: wplearninglab.com/wordpress-c...
Subscribe to this awesome channel here: kzitem.info_c...
Негізгі бет Custom Post Type Template - Create One To To Customize Designs
Пікірлер: 66