I recently released a plugin on WordPress.org that registers a portfolio post type, related taxonomies, and adds an image when you’re viewing the items in the dashboard.
I’ve held onto to the plugin for a while in GitHub since it’s an easy thing for any developer to build out- but I’ve recently been thinking that a standard plugin in the repository might be beneficial as it could make more themes more portable. (Especially for users of my Portfolio Press theme)
And since I expect people to modify this a bit as well, I wanted walk through of the code.
[gist id=”62036e1ef1ea6d79318b4c3b0ff9bae1″ file=”portfolio-post-type-gist.php” lines=”1-10″]
Explanation: All plugins need to have basic header data in order to show up in plugin admin page. If you don’t want to get updates to the plugin (I don’t expect many), change the name to something different. Shoot, feel free to change any of this- that’s why it’s being released!
Enable the Portfolio Post Type
[gist id=”62036e1ef1ea6d79318b4c3b0ff9bae1″ file=”portfolio-post-type-gist.php” lines=”12-44″]
This is the basic code needed to register the portfolio post type. I’ve wrapped it all in one function that fires on init. For a deeper explanation of all the arguments ($args) check out the codex post.
Wrapped in that same function I also register two taxonomies for categories and tags. Since that code is long, and basically just a bunch of labels I’ll point you to the actual code on GitHub. If you don’t want taxonomies, you don’t actually need that code.
Use Post Thumbnails
If you want your post type to be able to use thumbnails, you’ll need to register it:
[gist id=”62036e1ef1ea6d79318b4c3b0ff9bae1″ file=”portfolio-post-type-gist.php” lines=”46-47″]
View Thumbnail Images in Column View of Dashboard
For something like portfolio items, it’s nice to see the images when you’re scanning posts in the dashboard. I wrote about how that functionality works in a separate post.
Display a Custom Icon for Portfolio Menus
I was lucky enough to get Ben Dunkle (the designer of the WordPress icons), to make some portfolio icons for me for the first version of this plugin. Now, most plugins use dashicons for custom post types.
Custom Meta Boxes
This plugin doesn’t register any custom meta boxes, but those obviously might be useful if you want to include a link a website, or a purchase button, etc. If you’re interested in doing that- see my post on adding custom meta boxes to post types.