In a WordPress installation, by default, there are five post types that are readily available to users and/or internally used.
The most common post types in WordPress are:
- Posts(Post Type: ‘post’)
- Pages (Post Type: ‘page’)
Then there are the internal ones:
- Attachment (Post Type: ‘attachment’)
- Revision (Post Type: ‘revision’)
- Navigation menu (Post Type: ‘nav_menu_item’)
Custom post types are new post types that you can create and that are useful when:
- Some content you are posting just doesn’t look and feel like a post
- Some content does not need to be part of a chronological series of entries
- Categories and Tags don’t help you to group and sort a particular content
- You need additional fields to enter more information with your content
- Your content cannot be part of your pages
- You need to display a particular content differently than regular posts or pages.
How to create a Custom Post Type in Pinegrow WP
Custom post type is registered with Register post type action from Site section in WP panel. When you export your theme, Pinegrow will add code for posts type registration to functions.php.
So, to which element of our source HTML code do we add the Register post type action?
The best place is to add the action on the top level of the section where you plan to use the custom post type. (If you have a look at our PGWP-Landy template, you will find Register post type action on the section#details element which is used is to display features details in a carousel)
BODY is another good place to add Custom post type action, but as we can only add one Post type action per element in the tree, adding it to the relevant page section is currently the best solution.
So first, we select the relevant section in the tree and from the WP tab, in Site section, add Register post type action.
Now let’s have a detailed look at the settings of the Post Type:
Post Type: This is the name of your Post Type (ex: pgwp_activities)
Naming Best Practices
While it is convenient to use a simple custom post type identifier like product which is consistent with the identifiers of the default post types (post, page, revision, attachment and nav_menu_item), it is better if you prefix your identifier with a short namespace that identifies your plugin, theme or website that implements the custom post type.
- acme_product or aw_product for products post type used by a hypothetical ACMEWidgets.com website.
- eightfold_product or eft_product for products post type provided by a hypothetical EightFold theme.
- ai1m_product for products post type provided by a hypothetical All-in-One Merchant plugin.
Without namespacing your custom post type identifier, other post types in your website will more likely conflict with custom post types defined in another theme or plugin.
Reserved Post Type Identifiers
Avoid any custom post types whose identifier begins with wp_.
Do pay close attention to not having your custom post type identifier exceed 20 characters though
Name: Plural descriptive name for the post type (ex: Activities)
Singular name: Name for one object of this post type. (ex: Activity)
Description: A short descriptive summary of what the post type is. (ex: Post related to the Company Activities)
Public: Controls how the type is visible to authors and readers
Hierarchical: Whether the post type is hierarchical
Supports: This is the place where you select the default features that will be available within your Post Type. (Default: title and editor)
- editor (content)
- thumbnail (featured image)
- revisions: (will store revisions)
- page-attributes: (menu order, hierarchical must be active to show Parent option)
- post-formats: add post formats (see Post Formats)
Has archive: Enables post type archives (see Custom post type template files)
Show in menu: Where to show the post type in the admin menu.
Menu icon: The url to the icon to be used for this menu or the name of the icon from the iconfont.
A best practice in order to preserve the visual consistency in the administration menu is to use the Dashicon font which is included in WordPress.
From the Dashicon page, choose the one that is ok for your Post type and copy its name. For example, if you want the globe icon to be your menu icon, then the name is dashicons-admin-site.
Menu position: The position in the menu order the post type should appear. Show in menu must be activated. (Default position is below Comments)
- 5 – below Posts
- 10 – below Media
- 15 – below Links
- 20 – below Pages
- 25 – below comments
- 60 – below first separator
- 65 – below Plugins
- 70 – below Users
- 75 – below Tools
- 80 – below Settings
- 100 – below second separator
Taxonomies: Standard taxonomies like category and/or post_tag that will be used with this post type. (The default setting is no taxonomies.)
If you want to use Custom taxonomies, they still need to be registered with Register taxonomy action.
Now, save your template and export your Theme.
You can check the corresponding code in your functions.php file.
Your Custom Post type is available in your WordPress admin, and before creating a loop in your PGWP template, our advice is that you create a few posts of your custom type. It will ease your design process by providing you with some content for the tests.
Now, it is time to create your first loop with your custom content!
Last updated on October 1, 2015 at 6:58 pm