在Wordpress中創建一個新的文章類型非常容易,你只需要編輯修改正確的文件,我通常做的是創建一個新的插件(這是一個簡單的WordPress文件夾系統中的新文件夾),創建您的插件文件夾中的一個php文件具有相同的插件名稱。
這裏是創建一個空的崗位類型,你的情況這會是「書」的代碼
<?php
function dwwp_register_post_type() {
$args = array('public'=> true, 'label'=> 'Staff');
register_post_type('staff', $args);
}
add_action('init', 'dwwp_register_post_type');
如果要指定您的自定義後類型的詳細信息
:
<?php
//Exit if accessed directly
if (! defined('ABSPATH')) {
exit;
}
function dwwp_register_post_type() {
$singular = 'Job';
$plural = 'Jobs';
$slug = str_replace(' ', '_', strtolower($singular));
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New ' . $singular,
'view' => 'View ' . $singular,
'view_item' => 'View ' . $singular,
'search_term' => 'Search ' . $plural,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural .' found',
'not_found_in_trash' => 'No ' . $plural .' in Trash'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 10,
'menu_icon' => 'dashicons-businessman',
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => false,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
// 'capabilities' => array(),
'rewrite' => array(
'slug' => $slug,
'with_front' => true,
'pages' => true,
'feeds' => true,
),
'supports' => array(
'title',
'editor',
'author',
'custom-fields'
)
);
register_post_type($slug, $args);
}
add_action('init', 'dwwp_register_post_type');
也看看這個教程,如果你奮鬥... http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
祝你好運。
Thx爲有用的鏈接和解釋。我也發現http://www.wpbeginner.com/wp-tutorials/how-to-add-custom-meta-boxes-in-wordpress-posts-and-post-types/ – Ninda
不客氣。這是精神!!! –