您可以在插件文件夹中创建一个新文件夹,称为“自定义分类法”。创建名为“custom taxonomy”的文件。并将下面的代码粘贴到其中。单词“Image”和“Images”应替换为当前主题的自定义分类法的名称。
别忘了激活插件。此外,您可能需要更改“public”和“has\\u archive”等内容的真/假值。
/**
* Plugin Name: Custom Post Type
* Plugin URI: http://www.mywebsite.com/my-first-plugin
* Description: The very first plugin that I have ever created.
* Version: 1.0
* Author: Your Name
* Author URI: http://www.mywebsite.com
*/
function custom_post_type() {
$post_names = array(
\'slug\' => \'image\',
\'singular\' => __( \'Image\', \'plugin-name\' ),
\'plural\' => __( \'Images\', \'plugin-name\' )
);
register_post_type( strtolower($post_names[\'slug\']),
array(
\'labels\' => array(
\'name\' => $post_names[\'plural\'],
\'singular_name\' => $post_names[\'singular\'],
\'add_new\' => sprintf( __( \'Add new %s\', \'plugin-name\' ), strtolower($post_names[\'singular\']) ),
\'add_new_item\' => sprintf( __( \'Add new %s\', \'plugin-name\' ), strtolower($post_names[\'singular\']) ),
\'edit\' => sprintf( __( \'Edit %s\', \'plugin-name\' ), strtolower($post_names[\'singular\']) ),
\'edit_item\' => sprintf( __( \'Edit %s\', \'plugin-name\' ), strtolower($post_names[\'singular\'] )),
\'new_item\' => sprintf( __( \'New %s\', \'plugin-name\' ), strtolower($post_names[\'singular\'] )),
\'all_items\' => sprintf( __( \'All %s\', \'plugin-name\' ), strtolower($post_names[\'plural\'] )),
\'view\' => sprintf( __( \'View %s\', \'plugin-name\' ), strtolower($post_names[\'singular\'] )),
\'view_item\' => sprintf( __( \'View %s\', \'plugin-name\' ), strtolower($post_names[\'singular\'] )),
\'search_items\' => sprintf( __( \'Search %s\', \'plugin-name\' ), strtolower($post_names[\'plural\'] )),
\'not_found\' => sprintf( __( \'No %s found\', \'plugin-name\' ), strtolower($post_names[\'plural\']) ),
\'not_found_in_trash\' => sprintf( __( \'No %s found in trash\', \'plugin-name\' ), strtolower($post_names[\'plural\'] )),
\'parent_item_colon\' => \'\' /* text for parent types */
),
\'description\' => sprintf(__( \'Create an %s\', \'plugin-name\' ), strtolower($post_names[\'singular\'])),
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'publicly_queryable\' => true,
/* queries can be performed on the front end */
\'has_archive\' => true,
\'rewrite\' => array(),
\'menu_position\' => 5,
\'show_in_nav_menus\' => true,
\'menu_icon\' => \'dashicons-images-alt2\',
\'hierarchical\' => true,
\'query_var\' => true,
\'show_in_rest\' => true,
/* Sets the query_var key for this post type. Default: true - set to $post_type */
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'revisions\', \'excerpt\', \'page-attributes\'),
)
);
}
add_action( \'init\', \'custom_post_types\', 11 );