我已创建自定义帖子类型“item”:
function mywp_add_item_post() {
$labels = array(
\'name\' => \'Items\',
\'singular_name\' => \'Item\',
\'add_new\' => \'Add New Item\',
\'add_new_item\' => \'Add New Item\',
\'edit_item\' => \'Edit Item\',
\'new_item\' => \'New Item\',
\'all_items\' => \'All Items\',
\'view_item\' => \'View Item\',
\'search_items\' => \'Search Items\',
\'not_found\' => \'No Items Found\',
\'not_found_in_trash\' => \'No Items found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Items\',
\'show_in_nav_menus\'=>true
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'has_archive\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'rewrite\' => array(\'slug\' => \'item\'),
\'query_var\' => true,
\'menu_icon\' => \'dashicons-randomize\',
\'show_in_rest\' => true,
\'show_in_nav_menus\'=>true,
\'supports\' => array(\'title\', \'editor\', \'excerpt\', \'trackbacks\', \'custom-fields\', \'comments\', \'revisions\', \'thumbnail\', \'author\', \'page-attributes\'));
register_post_type( \'item\', $args );
}
add_action( \'init\', \'mywp_add_item_post\');
添加了名为“collection”的自定义分类:
function mywp_add_collection_taxonomy() {
$labels= array(\'name\' => _x( \'Collections\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Collection\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Collections\' ),
\'all_items\' => __( \'All Collection\' ),
\'parent_item\' => __( \'Parent Collection\' ),
\'parent_item_colon\' => __( \'Parent Collection:\' ),
\'edit_item\' => __( \'Edit Collection\' ),
\'update_item\' => __( \'Update Collection\' ),
\'add_new_item\' => __( \'Add New Collection\' ),
\'new_item_name\' => __( \'New Collection Name\' ),
\'menu_name\' => __( \'Collections\' ));
$rewrite= array(\'slug\' => \'collection\');
$args= array(\'hierarchical\' => true,
\'show_in_nav_menus\' => true,
\'has_archive\' => true,
\'labels\'=>$labels,
\'query_var\' => true,
\'show_in_rest\' => true,
\'rewrite\'=>$rewrite);
register_taxonomy(\'collection\', \'item\', $args);
}
function mywp_tax_filters()
{
register_taxonomy_for_object_type(\'collection\', \'item\');
}
add_action(\'init\', \'mywp_add_collection_taxonomy\', 1);
add_action(\'init\', \'mywp_tax_filters\');
Object: 我需要一个页面来查看非空的“集合”列表(如默认类别页面)
分类法模板文件(taxonomy collection.php)在主题目录中创建永磁线结构被冲洗我添加了一些“集合”,在其中分配“项目”Problem:链接“$site\\u url/collection”显示404(未找到)。
提前感谢您对我的问题的思考和耐心通读。