當網(wǎng)站有多個類型內(nèi)容的時候,可能需要用到Custom Post Type UI這個插件來分出幾個post type,但是如果想要在自定義的post type的文章內(nèi)容里面添加tag就需要做一下操作:
1、首先確保已安裝 Custom Post Type UI插件
2、安裝完插件以后進入后臺CPT UI —->Import/Export,在打開的頁面里面找到Get Code標簽,找到對應的post type代碼復制,然后放在主題目錄下面的functions.php文件下面
3、 對已復制的代碼進行修改:
add_action( 'init', 'cptui_register_my_cpts_application' ); function cptui_register_my_cpts_application() { $labels = array( "name" => "Applications", "singular_name" => "Application", ); $args = array( "labels" => $labels, "description" => "", "public" => true, "show_ui" => true, "show_in_rest" => true, "has_archive" => true, "show_in_menu" => true, "exclude_from_search" => false, "capability_type" => "post", "map_meta_cap" => true, "hierarchical" => true, "rewrite" => array( "slug" => "application", "with_front" => true ), "query_var" => true, "supports" => array( "title", "editor", "excerpt", "trackbacks", "custom-fields", "comments", "revisions", "thumbnail", "author", "page-attributes", "post-formats" ), "taxonomies" => array( "application-category" ), ); register_post_type( "application", $args ); // End of cptui_register_my_cpts_application() }
替換成一下代碼:
add_action( 'init', 'wpsites_custom_post_type' ); function wpsites_custom_post_type() { register_post_type( 'application', array( 'labels' => array( 'name' => __( 'Applications', 'wpsites' ), 'singular_name' => __( 'Application', 'wpsites' ), ), 'has_archive' => true, 'hierarchical' => true, 'menu_icon' => 'dashicons-heart', 'public' => true, 'rewrite' => array( 'slug' => 'application', 'with_front' => false ), 'supports' => array( "title", "editor", "excerpt", "trackbacks", "custom-fields", "comments", "revisions", "thumbnail", "author", "page-attributes", "post-formats" ), 'taxonomies' => array( 'application', 'post_tag' ), )); }