admin管理员组文章数量:1334335
I like to create a landing page for my custom taxonomies. Right now ive created three custom taxonomies
/country/[terms]
/person/[terms]
/interrests/[terms]
i like to create a listing page for each of the taxonomy, this listing page should list all the [terms] they contain. And link to the normal (taxonomy-[term].php
/taxonomy/[term]
) url. What is a proper way to implement this?
First i was thinking something along the lines with template_redirect and create a custom taxonomy-list.php
file to include in the action which manually query using a WP_Query()
I like to create a landing page for my custom taxonomies. Right now ive created three custom taxonomies
/country/[terms]
/person/[terms]
/interrests/[terms]
i like to create a listing page for each of the taxonomy, this listing page should list all the [terms] they contain. And link to the normal (taxonomy-[term].php
/taxonomy/[term]
) url. What is a proper way to implement this?
First i was thinking something along the lines with template_redirect and create a custom taxonomy-list.php
file to include in the action which manually query using a WP_Query()
2 Answers
Reset to default 4I can see at least 3 ways to do that.
Adding a rewrite rule. See http://codex.wordpress/Rewrite_API for details:
add_rewrite_rule('^(country|person|interest)/?','index.php?tax=$matches[1]','top');
then use the
template_redirect
filter to load your template when thetax
variable is there:if (get_query_var('tax')) { # load the template here }
You'll also need to add the
tax
query var to the list of filtered vars using thequery_vars
filter.Creating pages using specific template to list the terms
- Creating pages and use a shortcode to list the terms
In your case you need to create three custom files: taxonomy-country.php
, taxonomy-person.php
and taxonomy-interrests.php
.
Pay attention to suffixes of those templates. It has to be the same as in taxonomy registration. For instance if you register your taxonomy like register_taxonomy( 'genre', array( 'book' ), $args );
, then your custom template has to have taxonomy-genre.php
file name.
本文标签: template hierarchyTaxonomy landing pages
版权声明:本文标题:template hierarchy - Taxonomy landing pages 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742370117a2462069.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论