Creating a Portfolio Website with Custom Post Types
Joseph Dickson
joseph-dickson.com
linuxbookpro.com
@joe4ska
What is a Custom Post Type?
A Custom Post Type creates unique posts or pages for your website
Why Create Custom Post Types?
When you need more than standard Posts and Pages
A Portfolio in addition to casual blog posts.
Services that are in addition to casual pages
How do Custom Post Types Work in WordPress?
How To Create A Custom Post Type
As a Plugin*
*You can add it to a Theme as well
Creating a Portfolio Post Type
Custom Post Type Labels
name
– General Name
singular_name
– Name for one object of this post type
menu_name
– Label for Menu Name
Custom Post Type Labels
name_admin_bar
– Label for Admin Bar
add_new
– Label for adding a custom post or page in the dashboard
add_new_item
– Menu label for adding a new custom post or page from the menu
new_item
Menu lable label for admin bar menu.
Custom Post Type Labels
edit_item
– Edit label for dashboard
view_item
– View label for admin bar
all_items
– View all label for dashbord
search_items
– Search button label
Custom Post Type Labels
parent_item_colon
– parent label
not_found
– not found label
not_found_in_trash
not found in trash label
Custom Post Type Arguments
labels
– a variable to hold the labels listed in the previous examples.
public
– public visibility on front end
publicly_queryable
– public queries and whether they can be performed
show_ui
– display in admin user interface
Custom Post Type Arguments
show_in_menu
– visibility in navigation menus
menu_icon
– dashicons or graphic
query_var
– variations of slug if desired.
rewrite
– handling of rewrites
Custom Post Type Arguments
capability_type
– post or page.
has_archive
– archive index such as tags or categories.
hierarchical
– set if there is a parent / child page relationship for pages.
show_in_rest
– REST API / display in block editor
Custom Post Type Arguments
supports
‘title’
‘editor’ (content)
‘author’
‘thumbnail’ (featured image)
‘excerpt’
‘trackbacks’
‘custom-fields’
‘comments’
‘revisions’
‘page-attributes’ (menu order, hierarchical must be true to show Parent option)
‘post-formats’ (aside, video, qoute etc.)
Custom Post Type Arguments
menu_position
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
register_post_type
with WordPress
add_action
during init process
flushing rewrite on activation of plugin so permalinks function as expected
Creating a Services Post Type for Unique Pages and Workflow examples