WordPress 101 主题开发教程: 18 – 创建自定义文章类型Part1

WordPress 101 – Part 18: How to create Custom Post Type – Part 1

视频学习参考:https://www.youtube.com/watch?v=vSM7w3zzlSU&list=PLriKzYyLb28nUFbe0Y9d-19uVkOnhYxFE&index=18

1.在functions.php中加入

/**
* 自定文章
*/
function themes_custom_post_type() {
$labels = array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio',
'add_new' => 'Add Portfolio Item',
'all_items' => 'All Items',
'add_new_item' => 'Add Item',
'edit_item' => 'Edit Item',
'new_item' => 'New Item',
'view_item' => 'View Item',
'search_item' => 'Search Portfolio',
'not_found' => 'No Items Found',
'not_found_in_trash' => 'No Items Found In Trash',
'parent_item_colon' => 'Parent Item',
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'revisions',
),
'taxonomies' => array(
'category',
'post_tag',
),
'menu_position' => 5,
'exclude_from_search' => false,
);
register_post_type('portfolio', $args);
}
add_filter('init', 'themes_custom_post_type');

Happy coding!