我有一个叫CPT的Clubs
. 为了根据俱乐部是否参加同一联赛或杯赛(或两者都不参加)对帖子进行“分类”,我还有一个自定义分类法,名为Opposition
.
为了显示哪些俱乐部参加了相同的比赛,我正在尝试创建一个类似于存档页面的页面,其中Clubs
将显示帖子:/clubs/opposition/
为此,我创建了taxonomy-opposition.php
模板文件并编辑functions.php
文件包含以下内容:
// Clubs Post Type
function clubs_init() {
$labels = array(
\'name\' => \'Clubs\',
\'singular_name\' => \'Club\',
\'add_new\' => \'Add New Club\',
\'add_new_item\' => \'Add New Club\',
\'edit_item\' => \'Edit Club\',
\'new_item\' => \'New Club\',
\'all_items\' => \'All Clubs\',
\'view_item\' => \'View Club\',
\'search_items\' => \'Search Clubs\',
\'not_found\' => \'No Clubs Found\',
\'not_found_in_trash\' => \'No Clubs found in Trash\',
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Clubs\',
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'has_archive\' => false,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'taxonomies\' => array( \'clubs\', \'opposition\' ),
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'clubs\',
\'with_front\' => false
),
\'menu_icon\' => \'dashicons-shield\',
\'supports\' => array(
\'title\',
\'editor\',
\'excerpt\',
\'trackbacks\',
\'custom-fields\',
\'comments\',
\'revisions\',
\'thumbnail\',
\'author\',
\'page-attributes\'
)
);
register_post_type( \'clubs\', $args );
}
add_action( \'init\', \'clubs_init\' );
// Opposition Taxonomy
function opposition_taxonomy() {
$labels = array(
\'search_items\' => \'Search Opposition\',
\'menu_name\' => \'Opposition\'
);
register_taxonomy( \'opposition\', \'clubs\',
array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'query_var\' => true,
\'show_admin_column\' => true,
\'has_archive\' => true,
\'rewrite\' => array(
\'slug\' => \'clubs\',
\'with_front\' => false
),
) );
}
add_action( \'init\', \'opposition_taxonomy\' );
尝试访问时的结果
/clubs/opposition
, 不过,是一个错误404。让我困惑的是,我为我的
Players
CPT,创建自定义
Squad
显示的分类页面。我按照同样的步骤尝试创建
Opposition
页
(我已经冲洗了permalinks)
我已经提到了存在的问题,但到目前为止还没有找到解决方案: