admin管理员组文章数量:1392003
I am tweaking a theme for my friend, and I am using the following:
<?php $category = get_the_category(); ?> <h3 class="omc-blog-two-cat"><a href="<?php echo home_url(); echo ('/category/'.$category[0]->slug); ?>"><?php echo $category[0]->cat_name; ?></a></h3>
This gives website/category/categoryslug/, displaying the daughter category slug but I also want the parent category included as well. Ideally as website/category/parentcategory/daughtercategory
How can I achieve this? Many thanks :D
I am tweaking a theme for my friend, and I am using the following:
<?php $category = get_the_category(); ?> <h3 class="omc-blog-two-cat"><a href="<?php echo home_url(); echo ('/category/'.$category[0]->slug); ?>"><?php echo $category[0]->cat_name; ?></a></h3>
This gives website/category/categoryslug/, displaying the daughter category slug but I also want the parent category included as well. Ideally as website/category/parentcategory/daughtercategory
How can I achieve this? Many thanks :D
Share Improve this question asked Mar 25, 2020 at 21:16 ObsidianObsidian 376 bronze badges1 Answer
Reset to default 1There are functions for retrieving a term/category link (i.e. URL to the term archive page) and in the case of the default category
taxonomy, you can use get_category_link()
:
<a href="<?php echo esc_url( get_category_link( $category[0] ) ); ?>"><?php echo $category[0]->name; ?></a>
For custom taxonomies, you'd use get_term_link()
.
本文标签: categoriesNeed to pull parent category and slugonly pulling daughter category
版权声明:本文标题:categories - Need to pull parent category and slug - only pulling daughter category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744635950a2616823.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论