-1

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.com/category/main-category/child-category Example: www.example.com/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!

  • What is the question? – s_ha_dum Dec 14 '13 at 0:20
  • the question is what I want...and I don't know how to do it – whitelord Dec 14 '13 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" – whitelord Dec 14 '13 at 11:42
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; ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.