function get_terms_in_group($group_id, $taxon) { global $wpdb, $bp; $terms = array(); // $sql = "SELECT t.`id`, t.`name`, u.`count` // FROM {$bp->gtm->table_terms} AS t, {$bp->gtm->table_taxon} AS u // WHERE `group_id` = {$group_id} // AND `taxon` = {$taxon} // AND u.`count` = // (SELECT COUNT(DISTINCT `id`) // FROM ".$bp->gtm->table_taxon." // WHERE `term_id` = t.`id` // AND `group_id` = {$group_id} // ) // ORDER BY u.`count` DESC"; // echo $sql; $alldata = $wpdb->get_results($wpdb->prepare("\n SELECT DISTINCT `term_id` FROM {$bp->gtm->table_taxon} \n WHERE `group_id` = %d AND `taxon` = %s\n ORDER BY `term_id` ASC", $group_id, $taxon)); if (count($alldata) > 0) { foreach ($alldata as $temp) { $data[$temp->term_id]['id'] = $temp->term_id; } } // arsort($terms); $alldata2 = $wpdb->get_results($wpdb->prepare("\n SELECT `id`, `name` FROM {$bp->gtm->table_terms}\n WHERE `group_id` = %d AND `taxon` = %s\n ORDER BY `id` ASC", $group_id, $taxon)); foreach ($alldata2 as $temp2) { $terms[$temp2->id]['name'] = $temp2->name; $terms[$temp2->id]['id'] = $temp2->id; $terms[$temp2->id]['count'] = bp_gtm_count_term_usage($temp2->id, $group_id); } return $terms; }
function widget($args, $instance) { global $wpdb, $bp; if ($bp->gtm->slug == $bp->current_action) { extract($args); echo $before_widget; echo $before_title . $widget_name . $after_title; $data = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT `term_id`, `taxon` FROM {$bp->gtm->table_taxon}\n WHERE `group_id` = %d", $bp->groups->current_group->id)); if ($instance['display_count'] == 1) { $count = true; } else { $count = false; } // need to get all tags and cats separately if (count($data) != '0') { foreach ($data as $term) { if ($term->taxon == 'tag') { $tags[$term->term_id]->id = $term->term_id; } if ($term->taxon == 'cat') { $cats[$term->term_id]->id = $term->term_id; } } // lets work with tags if ($instance['display_tags'] == '1') { _e('<strong>Tags:</strong>', 'bp_gtm'); // display tags in a list if ($instance['display_type_tags'] == 'list') { echo '<ul id="disply-tags">'; if (count($tags) > 0) { foreach ($tags as $tag) { if ($instance['display_count'] == 1) { $count_func = ' (' . bp_gtm_count_term_usage($tag->id, $bp->groups->current_group->id) . ')'; } echo '<li>' . stripslashes(bp_gtm_get_term_name_by_id($tag->id, $link = true)) . $count_func . '</li>'; } } else { echo '<li>' . __('No tags to display', 'bp_gtm') . '</li>'; } echo '</ul>'; } elseif ($instance['display_type_tags'] == 'cloud') { // display tags in a cloud echo '<p>'; if (count($tags) > 0) { foreach ($tags as $tag) { echo stripslashes(bp_gtm_get_term_name_by_id($tag->id, $link = true, $count)) . ' '; } } else { echo '<li>' . __('No tags to display', 'bp_gtm') . '</li>'; } echo '</p>'; } } // now lets work with categories if ($instance['display_cats'] == '1') { _e('<strong>Categories:</strong>', 'bp_gtm'); if ($instance['display_type_cats'] == 'list') { echo '<ul id="disply-cats">'; if (count($cats) > 0) { foreach ($cats as $cat) { if ($instance['display_count'] == 1) { $count_func = ' (' . bp_gtm_count_term_usage($cat->id, $bp->groups->current_group->id) . ')'; } echo '<li>' . stripslashes(bp_gtm_get_term_name_by_id($cat->id, true)) . $count_func . '</li>'; } } else { echo '<li>' . __('No categories to display', 'bp_gtm') . '</li>'; } echo '</ul>'; } elseif ($instance['display_type_cats'] == 'cloud') { // display categories in a cloud echo '<p>'; if (count($cats) > 0) { foreach ($cats as $cat) { echo stripslashes(bp_gtm_get_term_name_by_id($cat->id, true, $count)) . ' '; } } else { echo '<li>' . __('No categories to display', 'bp_gtm') . '</li>'; } echo '</p>'; } } } else { echo '<div class="widget-error">' . __('There is nothing to display yet.', 'bp_gtm') . '</div>'; } echo $after_widget; } }