Q & R – display tags count

dev.xiligroup is being renovated Forums xili-tidy-tags plugin Q & R – display tags count

This topic contains 0 replies, has 4 voices, and was last updated by  Anonymous 8 years, 7 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2879

    xiligroup dev
    Keymaster

    The cloud uses basic wp tag cloud template tags (and class object) and extends it. Basically, the number is included in tooltip (title attribute of the link)… So to do that GW wishes, some hooks must be used… Just the time to find the good one…

    Be patient

    #2899

    Anonymous

    I’d vote for this as well, actually, I was trying to find a way out to do it myself today and I gave up, didn’t get it to show the count of posts per page, only in the title as you mentioned here :)

    #2901

    Anonymous

    The hook’s of WP are weird but very powerful… just the time to find time and to read source ;-)

    #2913

    Anonymous

    I came with a workaround for this issue :)

    However, some changes are required in the xili_tidy_tag_cloud function, if edited in the plugin folder, gonna be overwritten in the next update, the safest way to do so it to copy the whole function to theme’s function file after renaming it and go ahead, for me here I copied the same name and just added the letter ‘i’ in the beginning of the function name, my function now called ixili_tidy_tag_cloud

    Now, at the very end of your theme’s functions.php file copy this code as is:

    ‘function ixili_tidy_tag_cloud( $args =  » ) {

    if ( is_array($args) )

    $r = &$args;

    else

    parse_str($args, $r);

    $defaults = array(

    ‘smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 45,

    ‘format’ => ‘flat’, ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,

    ‘exclude’ =>  », ‘include’ =>  », ‘link’ => ‘view’, ‘tagsgroup’ =>  », ‘tagsallgroup’ =>  »

    );

    $r = array_merge($defaults, $r);

    extract($r); /* above changed because new args */

    if (($tagsgroup ==  » && $tagsallgroup ==  » ) || !function_exists(‘get_terms_of_groups_new’)) {

    $tags = get_tags( array_merge( $r, array( ‘orderby’ => ‘count’, ‘order’ => ‘DESC’ ) ) ); // Always query top tags

    } else {

    if ($tagsgroup != ») {

    $groupterm = is_term($tagsgroup,TAXOTIDYTAGS);

    $group_id[] = $groupterm;

    }

    if ($tagsallgroup != ») {

    $groupterm = is_term($tagsallgroup,TAXOTIDYTAGS);

    $group_id[] = $groupterm;

    }

    $tags = get_terms_of_groups_new ($group_id, TAXOTIDYTAGS,’post_tag’,array_merge( $r, array( ‘orderby’ => ‘count’, ‘order’ => ‘DESC’ )));

    }

    if ( empty( $tags ) )

    return;

    foreach ( $tags as $key => $tag ) {

    if ( ‘edit’ == $r )

    $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 = ixili_tidy_generate_tag_cloud( $tags, $r );

    if ( ‘array’ == $r )

    {return $return;}

    echo $return;

    }

    function ixili_tidy_generate_tag_cloud( $tags, $args =  » ) {

    global $wp_rewrite;

    $defaults = array(

    ‘smallest’ => 8, ‘largest’ => 22, ‘unit’ => ‘pt’, ‘number’ => 0,

    ‘format’ => ‘flat’, ‘separator’ => « n », ‘orderby’ => ‘name’, ‘order’ => ‘ASC’,

    ‘topic_count_text_callback’ => ‘default_topic_count_text’,

    ‘topic_count_scale_callback’ => ‘default_topic_count_scale’, ‘filter’ => 1,

    );

    if ( !isset( $args ) && isset( $args ) && isset( $args ) ) {

    $body = ‘return sprintf (

    _n(‘ . var_export($args, true) . ‘, ‘ . var_export($args, true) . ‘, $count),

    number_format_i18n( $count ));’;

    $args = create_function(‘$count’, $body);

    }

    $args = wp_parse_args( $args, $defaults );

    extract( $args );

    if ( empty( $tags ) )

    return;

    $tags_sorted = apply_filters( ‘tag_cloud_sort’, $tags, $args );

    if ( $tags_sorted != $tags ) {

    $tags = $tags_sorted;

    unset($tags_sorted);

    } else {

    if ( ‘RAND’ == $order ) {

    shuffle($tags);

    } else {

    if ( ‘name’ == $orderby )

    uasort( $tags, create_function(‘$a, $b’, ‘return strnatcasecmp($a->name, $b->name);’) );

    else

    uasort( $tags, create_function(‘$a, $b’, ‘return ($a->count > $b->count);’) );

    if ( ‘DESC’ == $order )

    $tags = array_reverse( $tags, true );

    }

    }

    if ( $number > 0 )

    $tags = array_slice($tags, 0, $number);

    $counts = array();

    $real_counts = array();

    foreach ( (array) $tags as $key => $tag ) {

    $real_counts[ $key ] = $tag->count;

    $counts[ $key ] = $topic_count_scale_callback($tag->count);

    }

    $min_count = min( $counts );

    $spread = max( $counts ) – $min_count;

    if ( $spread <= 0 )

    $spread = 1;

    $font_spread = $largest – $smallest;

    if ( $font_spread < 0 )

    $font_spread = 1;

    $font_step = $font_spread / $spread;

    $a = array();

    foreach ( $tags as $key => $tag ) {

    $count = $counts[ $key ];

    $real_count = $real_counts[ $key ];

    $tag_link = ‘#’ != $tag->link ? esc_url( $tag->link ) : ‘#’;

    $tag_id = isset($tags[ $key ]->id) ? $tags[ $key ]->id : $key;

    $tag_name = $tags[ $key ]->name;

    $a[] = « <a href=’$tag_link’ class=’tag-link-$tag_id’ title=' » . esc_attr( call_user_func( $topic_count_text_callback, $real_count ) ) . « ‘ style=’font-size:  » .

    ( $smallest + ( ( $count – $min_count ) * $font_step ) )

    . « $unit;’>$tag_name ( » . $topic_count_text_callback($real_count) . « ) »;

    }

    switch ( $format ) :

    case ‘array’ :

    $return =& $a;

    break;

    case ‘list’ :

    $return = « <ul class=’wp-tag-cloud’>nt

  • « ;

    $return .= join( « 

  • nt

  • « , $a );

    $return .= « 

  • nn »;

    break;

    default :

    $return = join( $separator, $a );

    break;

    endswitch;

    if ( $filter )

    return apply_filters( ‘wp_generate_tag_cloud’, $return, $tags, $args );

    else

    return $return;

    }’

    Now, each time you want to use the xili_tidy_tag_cloud() anywhere in your site, use the ixili_tidy_tag_cloud() instead and it will show the count next to each tag, all parameters such as: smallest, largest, format, tagsallgroup….etc all working just fine

    * Note that everytime you use the ixili_tidy_tag_cloud() you’ll get the post count next to tag’s name, if you want to show the xili tags cloud anywhere else in your site WITHOUT the count just use the simple xili_tidy_tag_cloud() and you’ll be OK :)

    @Michel: now you have the solution for displaying a count next to tag name, deploy it your way in the next version :)

#2914

Anonymous

@Michel: the code wrapper keep breaking with me and damage the page, fix it plz and it my previous post accordingly :)

#2917

Anonymous

the forum here is not totally dedicated to show a so large code… Can you create a post on your blog (using a plugin to color it) and comment this contribution…

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.