@asis,使用下面的函数。php添加CPT“travel”和tamx。。在它下面。
function travel()
{
$labels = array(
\'name\' => _x(\'travel\', \'post type general name\'),
\'singular_name\' => _x(\'Project\', \'post type singular name\'),
\'add_new\' => _x(\'Add New project\', \'Project\'),
\'add_new_item\' => __(\'Add New Project\'),
\'edit_item\' => __(\'Edit Project\'),
\'new_item\' => __(\'New Project\'),
\'all_items\' => __(\'All travel\'),
\'view_item\' => __(\'View Project\'),
\'search_items\' => __(\'Search travel\'),
\'not_found\' => __(\'No travel found\'),
\'not_found_in_trash\' => __(\'No travel found in Trash\'),
\'parent_item_colon\' => \'\',
\'menu_name\' => __(\'travel\')
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => 6,
\'menu_icon\' => \'\',
\'supports\' => array( \'title\', \'editor\', \'thumbnail\',\'comments\')
);
register_post_type(\'travel\',$args);
}
add_action( \'init\', \'travel\' );
function travel_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => _x( \'destinations\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'destinations\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search destinations\' ),
\'all_items\' => __( \'All destinations\' ),
\'parent_item\' => __( \'Parent destinations\' ),
\'parent_item_colon\' => __( \'Parent destinations:\' ),
\'edit_item\' => __( \'Edit destinations\' ),
\'update_item\' => __( \'Update destinations\' ),
\'add_new_item\' => __( \'Add New destination\' ),
\'new_item_name\' => __( \'New destination Name\' ),
\'menu_name\' => __( \'Destinations\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'destinations\' ),
);
register_taxonomy( \'destinations\', array(\'travel\' ), $args );
// 2nd taxo.. runs here
$labels = array(
\'name\' => _x( \'activities\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'activities\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search activities\' ),
\'all_items\' => __( \'All activities\' ),
\'parent_item\' => __( \'Parent activities\' ),
\'parent_item_colon\' => __( \'Parent activities:\' ),
\'edit_item\' => __( \'Edit activities\' ),
\'update_item\' => __( \'Update activities\' ),
\'add_new_item\' => __( \'Add New activity\' ),
\'new_item_name\' => __( \'New activity Name\' ),
\'menu_name\' => __( \'Activities\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'activities\' ),
);
register_taxonomy( \'activities\', array(\'travel\' ), $args );
// 3rd taxo.. runs here
$labels = array(
\'name\' => _x( \'packages\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'packages\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search packages\' ),
\'all_items\' => __( \'All packages\' ),
\'parent_item\' => __( \'Parent packages\' ),
\'parent_item_colon\' => __( \'Parent packages:\' ),
\'edit_item\' => __( \'Edit packages\' ),
\'update_item\' => __( \'Update packages\' ),
\'add_new_item\' => __( \'Add New package\' ),
\'new_item_name\' => __( \'New package Name\' ),
\'menu_name\' => __( \'Packages\' ),
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'packages\' ),
);
register_taxonomy( \'packages\', array(\'travel\' ), $args );
}
// hook
add_action( \'init\', \'travel_taxonomies\', 0 );