WordPress.org

Ready to get started?Download WordPress

Forums

Category Cloud Widget
Code snippet that makes plugin count sub-categories posts as well (1 post)

  1. rjakobsson
    Member
    Posted 2 years ago #

    if ( function_exists('get_categories') )
    {
    // new version of wp (2.1+)
    $cats = get_categories("style=cloud&show_count=1&use_desc_for_title=0$exclude&hierarchical=0$hide_empty");
    foreach ($cats as $cat)
    {
    // Get current category's children
    $children = get_categories('show_count=1&child_of='.$cat->cat_ID);
    $child_count = 0;
    
    if ($children != '') {
    foreach ($children as $child)
    {
    // Count the childrens post and add to total sum
    $child_count = $child_count + $child->category_count;
    }
    }
    $catlink = get_category_link( $cat->cat_ID );
    $catname = $cat->cat_name;
    $count = $cat->category_count;
    // Sum of count and all childrens counts
    $count = $count + $child_count;
    if ($count >= $options['min'])
    {
    $counts{$catname} = $count;
    $catlinks{$catname} = $catlink;
    }
    }
    }

    http://wordpress.org/extend/plugins/widget-category-cloud/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by rjakobsson
  • This topic is not a support question
  • WordPress version: 3.2.1