Ejemplo n.º 1
0
/**
 * Display tag cloud.
 *
 * The text size is set by the 'smallest' and 'largest' arguments, which will
 * use the 'unit' argument value for the CSS text size unit. The 'format'
 * argument can be 'flat' (default), 'list', 'nolink', or 'array'. The flat value for the
 * 'format' argument will separate tags with spaces. The list value for the
 * 'format' argument will format the tags in a UL HTML list. The nolink value for the
 * 'format' argument will display the tags without links. The array value for the
 * 'format' argument will return in PHP array type format.
 *
 * The 'orderby' argument will accept 'name' or 'count' and defaults to 'name'.
 * The 'order' is the direction to sort, defaults to 'ASC' and can be 'DESC'.
 *
 * The 'number' argument is how many tags to return. By default, the limit will
 * be to return the top 20 tags in the tag cloud list.
 *
 * The 'topic_count_text_callback' argument is a function, which, given the count
 * of the posts  with that tag, returns a text for the tooltip of the tag link.
 * @see default_topic_count_text
 *
 * The 'exclude' and 'include' arguments are used for the {@link get_tags()}
 * function. Only one should be used, because only one will be used and the
 * other ignored, if they are both set.
 *
 * @since 2.3.0
 *
 * @param array|string $args Optional. Override default arguments.
 * @return array Generated tag cloud, only if no failures and 'array' is set for the 'format' argument.
 */
function seo_tag_cloud($args = '')
{
    $defaults = array('largest' => 10, 'number' => 20, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'link' => 'view', 'target' => '');
    $args = wp_parse_args($args, $defaults);
    $tags = get_tags(array_merge($args, array('orderby' => 'count', 'order' => 'DESC')));
    // Always query top tags
    if (empty($tags)) {
        return;
    }
    foreach ($tags as $key => $tag) {
        if ('edit' == $args['link']) {
            $link = get_edit_tag_link($tag->term_id);
        } else {
            $link = get_tag_link($tag->term_id);
        }
        if (is_wp_error($link)) {
            return false;
        }
        $tags[$key]->link = $link;
        $tags[$key]->id = $tag->term_id;
    }
    $return = seo_tag_cloud_generate($tags, $args);
    // Here's where those top tags get sorted according to $args
    $return = apply_filters('wp_tag_cloud', $return, $args);
    if ('array' == $args['format']) {
        return $return;
    }
    echo $return;
}
Ejemplo n.º 2
0
 function widget_authors_cloud($args = '')
 {
     global $wpdb;
     $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'limit' => 0, 'posts_limit' => 0, 'em_step' => 0.1);
     $r = wp_parse_args($args, $defaults);
     extract($r, EXTR_SKIP);
     $return = '';
     $authors = $wpdb->get_results('SELECT ID, user_nicename, display_name FROM ' . $wpdb->users . ' ' . ($exclude_admin ? 'WHERE ID <> 1 ' : '') . 'ORDER BY display_name');
     $author_count = array();
     foreach ((array) $wpdb->get_results('SELECT DISTINCT post_author, COUNT(ID) AS count FROM ' . $wpdb->posts . ' WHERE post_type = "post" AND ' . get_private_posts_cap_sql('post') . ' GROUP BY post_author') as $row) {
         $author_count[$row->post_author] = $row->count;
     }
     foreach ((array) $authors as $key => $author) {
         $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
         if ($posts != 0 || !$hide_empty) {
             $author = get_userdata($author->ID);
             $name = $author->display_name;
             if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
                 $name = "{$author->first_name} {$author->last_name}";
             }
             if ($posts == 0) {
                 if (!$hide_empty) {
                     $link = '';
                 }
             } else {
                 $link = get_author_posts_url($author->ID, $author->user_nicename);
             }
             $authors[$key]->name = $name;
             $authors[$key]->count = $posts;
             $authors[$key]->link = $link;
             $authors[$key]->extra = $optioncount ? '(' . $posts . ')' : '';
         } else {
             unset($authors[$key]);
         }
     }
     $args['number'] = $limit;
     $return = seo_tag_cloud_generate($authors, $args);
     // Here's where those top tags get sorted according to $args
     echo $return;
 }
Ejemplo n.º 3
0
 function widget_authors_cloud($args = '')
 {
     $defaults = array('optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'limit' => 0, 'em_step' => 0.1, 'orderby' => 'name', 'exclude' => '"0"', 'include' => '');
     $r = wp_parse_args($args, $defaults);
     extract($r, EXTR_SKIP);
     $return = '';
     $authors = widget_authors_get_authors($include, $exclude);
     $author_count = widget_authors_count_authors($authors);
     widget_authors_sort_by($orderby, $authors);
     foreach ((array) $authors as $key => $author) {
         $posts = isset($author_count[$author->ID]) ? $author_count[$author->ID] : 0;
         if ($posts != 0 || !$hide_empty) {
             $author = get_userdata($author->ID);
             if ($exclude_admin && 10 == $author->user_level) {
                 continue;
             }
             $name = $author->display_name;
             if ($show_fullname && ($author->first_name != '' && $author->last_name != '')) {
                 $name = $author->first_name . ' ' . $author->last_name;
             }
             if ($posts == 0) {
                 if (!$hide_empty) {
                     $link = '';
                 }
             } else {
                 $link = get_author_posts_url($author->ID, $author->user_nicename);
             }
             $authors[$key]->name = $name;
             $authors[$key]->count = $posts;
             $authors[$key]->link = $link;
             $authors[$key]->extra = $optioncount ? '(' . $posts . ')' : '';
         } else {
             unset($authors[$key]);
         }
     }
     $args['number'] = $limit;
     $return = seo_tag_cloud_generate($authors, $args);
     // Here's where those top tags get sorted according to $args
     echo $return;
 }