页面未找到错误并不意味着未找到/使用模板文件。请注意,URL返回404状态标头(未找到),然后返回404。使用php(如果404.php不存在,则使用index.php)。
我认为您真正的问题是,在分类法注册之后,您没有刷新重写规则。要执行此操作,请执行以下步骤:
Manually: 转到设置->永久链接并单击保存按钮(无需更改任何内容,只需单击保存按钮)。
Auto: 在插件中,使用flush_rewrite_rules()
插件激活期间挂钩(切勿使用flush_rewrite_rules()
每次加载页面时)。例如:
register_activation_hook( __FILE__, \'cyb_plugin_activation\' );
function cyb_plugin_activation() {
cyb_register_taxonomy();
flush_rewrite_rules();
}
add_action( \'init\', \'cyb_register_taxonomy\' );
function cyb_register_taxonomy() {
$specialty_args = array(
\'hierarchical\' => false,
// This array of options controls the labels displayed in the WordPress Admin UI
\'labels\' => array(
\'name\' => \'Specialty\',
\'singular_name\' => \'Specialty\',
\'search_items\' => \'Search specialties\',
\'all_items\' => \'All specialties\',
\'edit_item\' => \'Edit specialty\',
\'update_item\' => \'Update specialty\',
\'add_new_item\' => \'Add new specialty\',
\'new_item_name\' => \'New specialty name\',
\'menu_name\' => \'Specialties\',
),
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => \'specialty\',
// Control the slugs used for this taxonomy
\'rewrite\' => array(
\'slug\' => \'events/specialty\', // This controls the base slug that will display before each term (renamed to specialty from specialties)
\'with_front\' => false, // Don\'t display the category base before "/specialties/"
\'hierarchical\' => false
),
);
register_taxonomy(\'specialty\', \'event\', $specialty_args);
register_taxonomy_for_object_type(\'specialty\', \'event\');
}
register_deactivation_hook( __FILE__, \'cyb_plugin_deactivation\' );
function cyb_plugin_deactivation() {
// Flush the rewrite rules also on deactivation
flush_rewrite_rules();
}