_add_post_type_submenus

函式
_add_post_type_submenus ( No parameters )

_add_post_type_submenus: 這個函式用於在WordPress管理選單中為特定的文章型別新增子選單。這些子選單被新增到主文章型別選單中,並允許快速導航到與該文章型別相關的重要區域。

為文章型別新增子選單。

function _add_post_type_submenus() {
	foreach ( get_post_types( array( 'show_ui' => true ) ) as $ptype ) {
		$ptype_obj = get_post_type_object( $ptype );
		// Sub-menus only.
		if ( ! $ptype_obj->show_in_menu || true === $ptype_obj->show_in_menu ) {
			continue;
		}
		add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
	}
}

常見問題

FAQs
檢視更多 >