admin管理员组文章数量:1130349
I need to create this structure:
- example/animals (with all animals classes)
- example/animals/classes (with all animals of this classes)
- example/animals/classes/animal_name (the animal's page)
I doubt that the following solution is correct:
I created a Custom post type "animals" with this rule 'rewrite' => array('slug' => 'animals/%classes%') where classes is my custom taxonomy.
And I added this filter to make the rewrite work.
function addTaxonomyInUrl($post_link, $id = 0) {
$post = get_post($id);
if(is_object($post) ) {
$terms = wp_get_object_terms($post->ID,'classes');
if($terms) {
return str_replace('%classes%', $terms[0]->slug, $post_link);
}
}
return $post_link;
}
add_filter ('post_type_link','addTaxonomyInUrl',1,3);
This works well except for two things:
1 - the page example/animals, I tried to create it as an archive temaplate of animals but dosen't work. (for the moment I workarounded the problem using a normale page)
2 - the rewite of animal's pages, example/animals/reptiles/python works well but if I change "reptiles" with something else ex. example/animals/foo/python I keep on seeing the Python page instead of a 404 error.
Could you plesse give me some suggestions?
I need to create this structure:
- example/animals (with all animals classes)
- example/animals/classes (with all animals of this classes)
- example/animals/classes/animal_name (the animal's page)
I doubt that the following solution is correct:
I created a Custom post type "animals" with this rule 'rewrite' => array('slug' => 'animals/%classes%') where classes is my custom taxonomy.
And I added this filter to make the rewrite work.
function addTaxonomyInUrl($post_link, $id = 0) {
$post = get_post($id);
if(is_object($post) ) {
$terms = wp_get_object_terms($post->ID,'classes');
if($terms) {
return str_replace('%classes%', $terms[0]->slug, $post_link);
}
}
return $post_link;
}
add_filter ('post_type_link','addTaxonomyInUrl',1,3);
This works well except for two things:
1 - the page example/animals, I tried to create it as an archive temaplate of animals but dosen't work. (for the moment I workarounded the problem using a normale page)
2 - the rewite of animal's pages, example/animals/reptiles/python works well but if I change "reptiles" with something else ex. example/animals/foo/python I keep on seeing the Python page instead of a 404 error.
Could you plesse give me some suggestions?
本文标签: Custom post type structurepermalink structure
版权声明:本文标题:Custom post type structure + permalink structure 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749228460a2336079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论