admin管理员组文章数量:1315304
I want to print (display) the child category slug, so I can use it in a dynamic url, on categories pages. So If I am on the category www.example/category/main-category/child-category Example: www.example/category/games/board-games
In the sidebar I will have a link Updates from Board Games so I need the code to simply display child-category slug, in this case is "board-games", and child category name, in this case is "Board Games"
on post pages it's simple, I have this code and it's working (maybe someone will find it useful)
<?php $cat_slug = get_the_category(); ?><a href="<?php echo get_bloginfo('url') . "/updates-from-" . $cat_slug[0]->category_nicename; ?>" > Updates from '<?php echo $cat_slug[0]->cat_name . "";?>'</a>
thank you for your help!
I want to print (display) the child category slug, so I can use it in a dynamic url, on categories pages. So If I am on the category www.example/category/main-category/child-category Example: www.example/category/games/board-games
In the sidebar I will have a link Updates from Board Games so I need the code to simply display child-category slug, in this case is "board-games", and child category name, in this case is "Board Games"
on post pages it's simple, I have this code and it's working (maybe someone will find it useful)
<?php $cat_slug = get_the_category(); ?><a href="<?php echo get_bloginfo('url') . "/updates-from-" . $cat_slug[0]->category_nicename; ?>" > Updates from '<?php echo $cat_slug[0]->cat_name . "";?>'</a>
thank you for your help!
Share Improve this question asked Dec 13, 2013 at 23:36 vyperlookvyperlook 1775 silver badges24 bronze badges 3- What is the question? – s_ha_dum Commented Dec 14, 2013 at 0:20
- the question is what I want...and I don't know how to do it – vyperlook Commented Dec 14, 2013 at 1:29
- is that hard to understand what the question is? "I want to print (display) the child category slug, so I can use it in a dynamic url, on categories pages" – vyperlook Commented Dec 14, 2013 at 11:42
1 Answer
Reset to default 0seems nobody understood 'my question', so I solved it myself here is the code for getting the slug I needed
<?php $cat = get_term_by('name', single_cat_title('',false), 'category'); echo $cat->slug; ?>
本文标签: categoriesPrint child category slug nicename
版权声明:本文标题:categories - Print child category slug nicename 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741978021a2408235.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论