我已经为我的网站创建了一个名为projects
使用名为taxonomy-projects.php
. 问题是当我浏览到http://mysite.com/projects
模板未触发,index.php
是,但当我浏览到http://mysite.com/projects/someterm
模板显示得很好。
当我浏览到时,如何显示我的模板http://mysite.com/projects
?
在你问之前。是的,我知道在进行更改之前需要清除重写规则。我通过在admin中保存永久链接设置来实现这一点。
以下是我创建自定义分类法的方式:
$args = array(
\'labels\' => array(
\'name\' => "Categories",
\'singular_name\' => "Category",
\'search_items\' => "Search Categories",
\'popular_items\' => "Popular Categories",
\'all_items\' => "All Categories",
\'parent_item\' => "Parent Category",
\'parent_item_colon\' => "Parent Category:",
\'edit_item\' => "Edit Category",
\'update_item\' => "Update Category",
\'add_new_item\' => "Add New Category",
\'new_item_name\' => "New Category Name",
),
\'hierarchical\' => TRUE,
\'label\' => \'Categories\',
\'query_var\' => TRUE,
\'rewrite\' => array(
\'slug\' => \'projects\'
),
);
register_taxonomy(\'projects\', \'project\', $args);
UPDATE:
我跟踪了
$wp_query->get_queried_object()
在每个页面上以及当我浏览到包含术语的页面时,例如
http://mysite.com/projects/commercial
我得到以下输出:
stdClass Object
(
[term_id] => 4
[name] => Commercial
[slug] => commercial
[term_group] => 0
[term_taxonomy_id] => 8
[taxonomy] => projects
[description] =>
[parent] => 0
[count] => 1
)
但是,当我浏览到
http://mysite.com/projects
输出值为零。
我不明白我做错了什么。我怎样才能taxonomy-projects.php
浏览到时显示http://mysite.com/projects
?