0

I want to display a select box to switch to SUBCATEGORIES of the current CATEGORY when i'm on a category page.

I've the following category structure

Category 1
    Subcategory 1
    Subcategory 2
    Subcategory 3
Category 2
    Subcategory 1
    Subcategory 2

I've created a custom template using the category slug but i need to create a selectbox at the top of the template that loads the subcategory of the current category. How do i achieve this?

1

If you are referring to the categories from the post type post (the blog) then this would do the trick:

For a drop-down: wp_dropdown_categories()

For a list: wp_list_categories()

child_of
Only display categories that are children of the category identified by this parameter. There is no default for this parameter.

<?php 
  // Put the parent category ID in place of 9999
  // for a drop-down, does not need <select></select> wrapper
  wp_dropdown_categories('child_of=9999');
  // for a list, does need <ul></ul> wrapper
  wp_list_categories('child_of=9999');
?>
0

I can't comment on deflime's answer, but if you want a <select> you'll want to use the wp_dropdown_categories function

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.