- Registering post type in function.php
- Create custom related pages.
- Settings->Permalinks [Update]
Done!
This post improved version of previous Creating WordPress Custom Post Type | Basic
Let's start...
- Modifie, functions.php (in child theme) to register Custom Post Type
1234567891011121314151617181920212223242526272829303132333435363738394041424344// Register Custom Post Typefunction custom_post_type() {$labels = array('name' => _x( 'Products', 'Post Type General Name', 'text_domain' ),'singular_name' => _x( 'Product', 'Post Type Singular Name', 'text_domain' ),'menu_name' => __( 'Product', 'text_domain' ),'parent_item_colon' => __( 'Parent Product:', 'text_domain' ),'all_items' => __( 'All Products', 'text_domain' ),'view_item' => __( 'View Product', 'text_domain' ),'add_new_item' => __( 'Add New Product', 'text_domain' ),'add_new' => __( 'New Product', 'text_domain' ),'edit_item' => __( 'Edit Product', 'text_domain' ),'update_item' => __( 'Update Product', 'text_domain' ),'search_items' => __( 'Search products', 'text_domain' ),'not_found' => __( 'No products found', 'text_domain' ),'not_found_in_trash' => __( 'No products found in Trash', 'text_domain' ),);$args = array('label' => __( 'product', 'text_domain' ),'description' => __( 'Product information pages', 'text_domain' ),'labels' => $labels,'supports' => array( ),'taxonomies' => array( 'category', 'post_tag' ),'hierarchical' => false,'public' => true,'show_ui' => true,'show_in_menu' => true,'show_in_nav_menus' => true,'show_in_admin_bar' => true,'menu_position' => 5,'menu_icon' => '','can_export' => true,'has_archive' => true,'exclude_from_search' => false,'publicly_queryable' => true,'capability_type' => 'page',);register_post_type( 'product', $args );}// Hook into the 'init' actionadd_action( 'init', 'custom_post_type', 0 ); - Create custom template files (copy and rename archive.php and single.php as below)
- single posts of a custom post type will use single-mycompany_product.php
- and their archives will use archive-mycompany_product.php
- Navigate in WP-Admin menu to: Settings->Permalinks. Update page, this will rewrite .htaccess