【发布时间】:2019-01-03 23:32:26
【问题描述】:
我使用此代码注册了一个自定义帖子类型:
register_post_type( 'gallerydoc', array(
'labels' => array(
'name' => __( 'Gallery Docs' ),
'singular_name' => __( 'Gallery Doc' )
),
'public' => true,
'publicly_queryable' => false,
// '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
// '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
'capability_type' => 'page',
'map_meta_cap' => true,
'menu_position' => 20,
'hierarchical' => true,
'rewrite' => false,
'query_var' => false,
'delete_with_user' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
'show_in_rest' => true,
'rest_base' => 'pages',
'rest_controller_class' => 'WP_REST_Posts_Controller',
) );
我从注册页面类型的functions.php 复制了代码。
我唯一注释掉的是“仅供内部使用。请勿使用”的行。
但自定义类型的行为仍然不像页面或帖子类型。
自定义帖子类型:
- 无法编辑永久链接
- 在站点根目录下没有 slug
- 没有选择模板页面
我读到自定义帖子类型不能将它们的 slug 直接放在根目录下:
Wordpress - Page and custom post type with this same slug
因为这会与页面和帖子发生冲突。但是,嘿,页面和帖子可以很好地相互配合。
那么为什么我的自定义帖子类型也不能这样做呢?
【问题讨论】:
标签: wordpress