英寸archive.php
文件,我想知道,我在哪种类型的档案中。例如,如果我在类别存档中Personal 我希望能够在档案的标题中显示它。当然,我可以创建如下文件category-12.php
, category-13.php
... 然后在文件中对其进行harcode,但这似乎不是很好的代码重用示例。感谢您的回答。
找出我在哪种档案中
1 个回复
最合适的回答,由SO网友:fuxia 整理而成
检查get_queried_object()
.
在类别的存档上Uncategorized
你会得到像…
stdClass Object
(
[term_id] => 1
[name] => Uncategorized
[slug] => uncategorized
[term_group] => 0
[term_taxonomy_id] => 1
[taxonomy] => category
[description] =>
[parent] => 0
[count] => 8
[cat_ID] => 1
[category_count] => 8
[category_description] =>
[cat_name] => Uncategorized
[category_nicename] => uncategorized
[category_parent] => 0
)
…并保存在标签的存档中test
…stdClass Object
(
[term_id] => 18
[name] => test
[slug] => test-2
[term_group] => 0
[term_taxonomy_id] => 18
[taxonomy] => post_tag
[description] =>
[parent] => 0
[count] => 1
)
因此,您可以测试属性taxonomy
因为该对象存在,其值是什么。然后调整模板。结束