As we know wordpress contain post and pages as their primary substance. They are main content type in wordpress .But we can also make our own custom content types these are called custom post types.
They are similar to post and pages . We can create our own custom content types and can name them whatever we want . For example if we are working on a portfolio website then we need to create a portfolio post type.
By using below code we can create a portfolio post type. We have to put below code in our function.php file.
add_action( 'init', 'codex_Portfolio_init' );
/**
* Register a Portfolio post type.
*
* @link http://codex.wordpress.org/Function_Reference/register_post_type
*/
function codex_Portfolio_init() {
$labels = array(
'name' => _x( 'Portfolios', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Portfolio', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Portfolios', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Portfolio', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Add New', 'Portfolio', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Add New Portfolio', 'your-plugin-textdomain' ),
'new_item' => __( 'New Portfolio', 'your-plugin-textdomain' ),
'edit_item' => __( 'Edit Portfolio', 'your-plugin-textdomain' ),
'view_item' => __( 'View Portfolio', 'your-plugin-textdomain' ),
'all_items' => __( 'All Portfolios', 'your-plugin-textdomain' ),
'search_items' => __( 'Search Portfolios', 'your-plugin-textdomain' ),
'parent_item_colon' => __( 'Parent Portfolios:', 'your-plugin-textdomain' ),
'not_found' => __( 'No Portfolios found.', 'your-plugin-textdomain' ),
'not_found_in_trash' => __( 'No Portfolios found in Trash.', 'your-plugin-textdomain' )
);
$args = array(
'labels' => $labels,
'description' => __( 'Description.', 'your-plugin-textdomain' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-smiley',
'query_var' => true,
'rewrite' => array( 'slug' => 'portfolio' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'portfolio', $args );
}
0 Comment(s)