WordPress.org

Forums

Category cloud for direct sub-categories of a certain category (3 posts)

  1. renet
    Member
    Posted 3 years ago #

    Hey everybody,

    I'd like to get a category cloud for all direct sub-categories (only the next level) of the category (archive) that I'm viewing at the moment. Is this possible using the wp_tag_cloud function?

    Thanks in advance,
    René

  2. renet
    Member
    Posted 3 years ago #

    Nobody got an idea? Any simple alternatives are welcome. :)

  3. jgme
    Member
    Posted 3 years ago #

    This will work:

    <?php
    $childcategories = get_categories('child_of=' . $cat . '&hide_empty=1');
    foreach ($childcategories as $childcategory) {
    if (in_category($childcategory)) {
    $childs  = array($childcategory->cat_ID);
    foreach($childs as $idofchild){$string .= $idofchild.',';} } }
    $args = array( 'taxonomy' => 'category','include' => $string);
    wp_tag_cloud( $args);
     ?>

    And here a Version for all descendant categories:

    <?php
    $childcategories = get_categories('child_of=' . $cat . '&hide_empty=1');
    foreach ($childcategories as $childcategory) {
    $childs  = array($childcategory->cat_ID);
    foreach($childs as $idofchild){$string .= $idofchild.',';} }
    $args = array( 'taxonomy' => 'category','include' => $string);
    wp_tag_cloud( $args);
     ?>

Topic Closed

This topic has been closed to new replies.

About this Topic