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
Add a comment  | 

1 Answer 1

Reset to default 0

seems 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