Integrating post types is simply a matter of including the register_post_type function. Once you have included this in your functions.php file, your nav menu should go from something like this:
to this:

WordPress Navigation with Custom Post Type
In order to create custom post types, open your template’s functions.phpfile in an editor, and place the following function within the file:
function create_post_type() {
register_post_type( 'mysite_reviews',
array(
'labels' => array(
'name' => __( 'Reviews' ),
'singular_name' => __( 'Review' )
),
'public' => true,
'menu_position' => 5,
'rewrite' => array('slug' => 'reviews')
)
);
}
add_action( 'init', 'create_post_type' );
Broken down, this adds the function create_post_type, and registers the post type mysite_reviews.
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'mysite_reviews',
You may wonder why I’ve named the post_type mysite_reviews, and not just reviews. I made the name more conspicuous in order to make sure that my post type wouldn’t interfere with custom post type names from other plugins or themes.
Here is a summary of the important post type parameters I’ve set above:
- labels – WordPress allows us to label everything from the post type’s name to the label for adding new posts. A complete list can be found here. In the above function, I labeled the name of the post type and its singular name.
- public – If set to true
- menu_position – I set this to 5, which will place the post type directly under “Posts”. The other placements are as follows: null (below Comments), 0 (below Media), 20 (below Pages), 60 (below first separator) and 100 (below second separator)
- rewrite – So that our actual term “mysite_reviews” doesn’t get put in the URL, we set the slug to “reviews” which will be much better in the long run for our visitors, links, and SEO.
This is a part of WordPress Post Types and Taxonomies tutorial.
The post WordPress Post Types and Taxonomies – Integrating Post Types appeared first on Tutorial Mini.
Related posts:
- WordPress Post Types and Taxonomies
- WordPress Multisite Network With Multiple Domains
- WordPress Excerpts – Replace [...] by the link “Read More”
via Tutorial Mini http://tutorialmini.com/wordpress-post-types-and-taxonomies-integrating-post-types/
No comments:
Post a Comment