以下是我在主题功能中添加的代码。php文件
// Taxonomy Resource
$labels = array(
\'name\' => \'Resources\',
\'singular_name\' => \'Resource\',
\'search_items\' => \'Search Resource\',
\'all_items\' => \'All Resource\',
\'parent_item\' => \'Parent Resource\',
\'parent_item_colon\' => \'Parent Resource:\',
\'edit_item\' => \'Edit Resource\',
\'update_item\' => \'Update Resource\',
\'add_new_item\' => \'Add New Resource\',
\'new_item_name\' => \'New Resource Name\',
\'menu_name\' => \'Resource\',
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'resource\', \'with_front\' => false ),
);
register_taxonomy( \'resource\', array( \'post\' ), $args );
我使用以下代码行在前端显示它
<?php echo get_the_term_list( $post->ID, \'resource\', \'Resource: \', \', \' ); ?>
当我单击前端的资源项时,它会生成如下url:
http://site-name/resource/test/但它没有显示默认的归档模板,而是显示404页。之后我创建了taxonomy-resource.php
文件并从中复制代码archrive.php
结果是一样的,它给出了404页。