您可以使用创建自定义帖子类型register_post_type() 具有的函数false
像show_ui
像这样的参数。
//code is taken from codex
//custom post type name is book here. Change the post type name and other options as your need
//Set `show_ui` and `show_in_menu` false
add_action( \'init\', \'codex_book_init\' );
function codex_book_init() {
$labels = array(
\'name\' => _x( \'Books\', \'post type general name\', \'your-plugin-textdomain\' ),
\'singular_name\' => _x( \'Book\', \'post type singular name\', \'your-plugin-textdomain\' ),
\'menu_name\' => _x( \'Books\', \'admin menu\', \'your-plugin-textdomain\' ),
\'name_admin_bar\' => _x( \'Book\', \'add new on admin bar\', \'your-plugin-textdomain\' ),
\'add_new\' => _x( \'Add New\', \'book\', \'your-plugin-textdomain\' ),
\'add_new_item\' => __( \'Add New Book\', \'your-plugin-textdomain\' ),
\'new_item\' => __( \'New Book\', \'your-plugin-textdomain\' ),
\'edit_item\' => __( \'Edit Book\', \'your-plugin-textdomain\' ),
\'view_item\' => __( \'View Book\', \'your-plugin-textdomain\' ),
\'all_items\' => __( \'All Books\', \'your-plugin-textdomain\' ),
\'search_items\' => __( \'Search Books\', \'your-plugin-textdomain\' ),
\'parent_item_colon\' => __( \'Parent Books:\', \'your-plugin-textdomain\' ),
\'not_found\' => __( \'No books found.\', \'your-plugin-textdomain\' ),
\'not_found_in_trash\' => __( \'No books found in Trash.\', \'your-plugin-textdomain\' )
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => false,
\'show_in_menu\' => false,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'book\' ),
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
);
register_post_type( \'book\', $args );
}
这样,它就不会显示在管理菜单中。但您仍然可以将其与如下url一起使用
example.com/wp-admin/edit.php?post_type=book
.
您可以创建单独的模板single-book.php
按您喜欢的方式显示。您还可以像处理页面一样,使用id创建单独的文件。
如果您有一组属于同一类别的文件,则可以使用register_taxonomy() 创建分类法并为这些页面组使用不同的模板。
我相信这满足了您的所有要求:
它不显示在管理菜单中
您可以使用所有wordpress函数为每个页面(或页面组,如果需要,使用自定义分类法)创建单独的php代码