wordpress: how to retrieve only categories child of a given one

Filtering the list of categories is pretty easy.

To retrieve only categories child of a specific one, proceed as follow:

  1. log into wordpress
  2. go to ‘categories’
  3. click on ‘edit’ for the category you consider as top one
  4. in the url, check the value of “tag_ID“, this is your category id (22 in this example)
  5. in your code, where you are making a call to “wp_list_categories()” simply add the “child_of” argument as follow:
    wp_list_categories("child_of=$your_top_category_id");

    in this example: wp_list_categories(‘child_id=22’);

  6. that’s it!

Additional customization is possible since a bunch of configuration variables (including category nesting, number of posts in a category, …) are available as defined here: http://codex.wordpress.org/Function_Reference/dynamic_sidebar

sources

Post a Comment

Your email is never published nor shared. You're allow to say what you want...


Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/remydamo/websites/qc4blog/www/wp-content/plugins/sweetcaptcha-revolutionary-free-captcha-service/library/sweetcaptcha.php on line 81

Warning: fsockopen() [function.fsockopen]: unable to connect to www.sweetcaptcha.com:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/remydamo/websites/qc4blog/www/wp-content/plugins/sweetcaptcha-revolutionary-free-captcha-service/library/sweetcaptcha.php on line 81