When Custom Post Types was introduced in WordPress 3.0, it took WordPress to the whole new level. Instead of just a blogging platform, Custom Post Type gives more flexibility and extends WordPress to be a CMS. It helps to distinguish different types of content on your WordPress site - Post, Page, Attachment, Revision and Navigation Menu - thus make it easier to manage your content.
For example, if you are a Web Design agency, you probably want to showcase your portfolio on your site. By creating a Portfolio custom post type, it’ll make it easier for you to manage your portfolio by differentiating it from other posts or pages. The CPT can be added to your WordPress site via register_post_type
function.
In this example, we’ll show you how to create a simple Portfolio custom post type. Of course, you can change the name to anything you want.
SImply put the following code in your functions.php
file or even better your functionality plugin:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
There are lots of parameters can be accepted by the function to further customize your Custom Post Type. Please see the WordPress Codex for more info.
Here’s another example with lot more parameters:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
Of course, you do not need to remember each and every single code. There are few tools available to generate the code for you. For example, take a look at the CPT Generator Tool we introduced before or the one by Themergency.
We just showed you how to create a simple CPT. Of course, there are lots more you can do such as adding custom taxonomies, metabox and more.
Leave a Reply