所以我一直在WordPress网站上工作,我需要一个文档自定义帖子,该帖子应该注册为“文档”。我在插件Meta框中生成了自定义帖子的代码,并将代码放在了我的函数中。php文件(尽管在测试时,我禁用了Meta-Box,以查看它是否有干扰,同时保留它在functions.php中生成的php)。我有一个模板,一个文档。php文件,在我的主题的根目录中(如果有区别的话,它是一个子主题)。但WordPress一直默认为single。php,即使在刷新permalinks之后。
这是为添加自定义帖子而生成的代码元框:
function register_document() {
$args = array (
\'label\' => esc_html__( \'Documents\', \'mb86\' ),
\'labels\' => array(
\'menu_name\' => esc_html__( \'Documents\', \'mb86\' ),
\'name_admin_bar\' => esc_html__( \'Document\', \'mb86\' ),
\'add_new\' => esc_html__( \'Add new\', \'mb86\' ),
\'add_new_item\' => esc_html__( \'Add new Document\', \'mb86\' ),
\'new_item\' => esc_html__( \'New Document\', \'mb86\' ),
\'edit_item\' => esc_html__( \'Edit Document\', \'mb86\' ),
\'view_item\' => esc_html__( \'View Document\', \'mb86\' ),
\'update_item\' => esc_html__( \'Update Document\', \'mb86\' ),
\'all_items\' => esc_html__( \'All Documents\', \'mb86\' ),
\'search_items\' => esc_html__( \'Search Documents\', \'mb86\' ),
\'parent_item_colon\' => esc_html__( \'Parent Document\', \'mb86\' ),
\'not_found\' => esc_html__( \'No Documents found\', \'mb86\' ),
\'not_found_in_trash\' => esc_html__( \'No Documents found in Trash\', \'mb86\' ),
\'name\' => esc_html__( \'Documents\', \'mb86\' ),
\'singular_name\' => esc_html__( \'Document\', \'mb86\' ),
),
\'public\' => true,
\'description\' => \'Handbooks, manuals, and other documents.\',
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'show_in_rest\' => true,
\'menu_icon\' => \'dashicons-book-alt\',
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'has_archive\' => true,
\'query_var\' => true,
\'can_export\' => true,
\'rewrite_no_front\' => false,
\'supports\' => array(
\'title\',
\'thumbnail\',
),
\'rewrite\' => true,
);
register_post_type( \'document\', $args );
}
add_action( \'init\', \'register_document\' );
由于解决此问题的大多数主题都集中在更新permalinks上(我已经多次尝试),因此我不确定如何解决此问题。有什么想法吗?