WordPress MU: aggregate individual blogs Tag cloud

It could never happen have to aggregate the individual tag cloud by WordPress MU. In addition, in certain contexts, it may not make sense to show a "cloud" with the tag blog heterogeneous. However, in the unlikely event that someone was for, so here is a simple way to show a tag cloud aggregate.

The tag cloud standards WordPress

First of all let's see what WordPress uses to display the tag cloud standards: the function wp_tag_cloud() :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/ **
* Display tag cloud.
*
* The text size is set by the 'smallest' and 'largest' arguments, which effectively will
* Use the 'unit' argument value for the CSS text size unit. The 'format'
* Argument can be 'flat' (default), 'list', or 'arrays'. 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 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 45 tags in the tag cloud list.
*
* The 'topic_count_text_callback' argument is a function, which effectively, Given the count
* With That posts of the 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. Should Be Used Only One, Only One Will Be Because the used and
* Other ignored, if They Are Both in September
*
* @ Since 2.3.0
*
* @ Param array | string $ args Optional. Override the default arguments.
* @ Return array Generated tag cloud, only if no failures and 'array' is Set for the 'format' argument.
* /
$args = '' ) { wp_tag_cloud function ($ args ='') {
array ( $ Defaults = array (
8 , 'largest' => 22 , 'unit' => 'pt' , 'number' => 45 , 'Smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'flat' , 'orderby' => 'name' , 'order' => 'ASC' , 'Format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'' , 'include' => '' , 'link' => 'view' 'Exclude' =>'', 'include' =>'', 'link' => 'view'
);
wp_parse_args ( $args , $defaults ) ; $ Args = wp_parse_args ($ args, $ defaults);

get_tags ( array_merge ( $args , array ( 'orderby' => 'count' , 'order' => 'DESC' ) ) ) ; // Always query top tags $ Tags = get_tags ( array_merge ($ args, array ('orderby' => 'count', 'order' => 'DESC'))) / / Always query top tags

empty ( $tags ) ) if ( empty ($ tags))
return;

$tags as $key => $tag ) { foreach ($ tags as $ key => $ tag) {
'edit' == $args [ 'link' ] ) if ('edit' == $ args ['link'])
get_edit_tag_link ( $tag -> term_id ) ; $ Link = get_edit_tag_link ($ tag -> term_id);
else
get_tag_link ( $tag -> term_id ) ; $ Link = get_tag_link ($ tag -> term_id);
is_wp_error ( $link ) ) if (is_wp_error ($ link))
; return false;

$key ] -> link = $link ; $ Tags [$ key] -> link = $ link;
$key ] -> id = $tag -> term_id ; $ Tags [$ key] -> id = $ tag -> term_id;
}

wp_generate_tag_cloud ( $tags , $args ) ; // Here's where those top tags get sorted according to $args Wp_generate_tag_cloud $ return = ($ tags, $ args) / / Here's where the top tags get sorted Those According To $ args

apply_filters ( 'wp_tag_cloud' , $return , $args ) ; $ Return = apply_filters ('wp_tag_cloud', $ return, $ args);

'array' == $args [ 'format' ] ) if ('array' == $ args ['format'])
; return $ return;

; echo $ return;
}

If we look at the code we see that the key issues are: the recovery of tags

1
get_tags ( array_merge ( $args , array ( 'orderby' => 'count' , 'order' => 'DESC' ) ) ) ; // Always query top tags $ Tags = get_tags ( array_merge ($ args, array ('orderby' => 'count', 'order' => 'DESC'))) / / Always query top tags

che genera effettivamente la “nuvola”. The array $tags is then used by the function wp_generate_tag_cloud() that actually generates the "cloud".

Change for WordPress MU

Slightly modifying this function, we can get a cloud of tags that includes all our blogs:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/ **
* Aggregate individual tag cloud of all blogs
*
* @ Return
* @ Param object $ args [optional]
* /
$args = '' ) { wpmu_tag_cloud function ($ args ='') {
array ( $ Defaults = array (
8 , 'largest' => 22 , 'unit' => 'pt' , 'number' => 45 , 'Smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
'flat' , 'orderby' => 'name' , 'order' => 'ASC' , 'Format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
'' , 'include' => '' , 'link' => 'view' 'Exclude' =>'', 'include' =>'', 'link' => 'view'
);
wp_parse_args ( $args , $defaults ) ; $ Args = wp_parse_args ($ args, $ defaults);

/ / Get list of all blogs
get_blog_list ( 0 , 9999 ) ; $ Blog_list get_blog_list = (0, 9999);

array ( ) ; $ Tags = array ();

/ / For each of the blogs retrieves tags
$blog_list as $key => $blog ) { foreach ($ blog_list as $ key => $ blog) {
$blog [ 'blog_id' ] ; Blog_id = $ $ blog ['blog_id'];
/ / Select the blog
) ; switch_to_blog ($ blog_id);
get_tags ( array_merge ( $args , array ( 'orderby' => 'count' , 'order' => 'DESC' ) ) ) ; // Always query top tags Single_blog_tags get_tags = $ ( array_merge ($ args, array ('orderby' => 'count', 'order' => 'DESC'))) / / Always query top tags

$single_blog_tags as $key => $tag ) { foreach ($ single_blog_tags as $ key => $ tag) {
'edit' == $args [ 'link' ] ) if ('edit' == $ args ['link'])
get_edit_tag_link ( $tag -> term_id ) ; $ Link = get_edit_tag_link ($ tag -> term_id);
else
get_tag_link ( $tag -> term_id ) ; $ Link = get_tag_link ($ tag -> term_id);
is_wp_error ( $link ) ) return false ; if (is_wp_error ($ link)) return false;

$key ] -> link = $link ; Single_blog_tags $ [$ key] -> link = $ link;
$key ] -> id = $tag -> term_id ; Single_blog_tags $ [$ key] -> id = $ tag -> term_id;
}

/ / Merges the individual tag list in a single list
array_merge ( $single_blog_tags , $tags ) ; $ Tags = array_merge ($ single_blog_tags, $ tags);
}

/ / Call the standard function of WordPress
wp_generate_tag_cloud ( $tags , $args ) ; Wp_generate_tag_cloud $ return = ($ tags, $ args);

apply_filters ( 'wp_tag_cloud' , $return , $args ) ; $ Return = apply_filters ('wp_tag_cloud', $ return, $ args);

'array' == $args [ 'format' ] ) if ('array' == $ args ['format'])
; return $ return;

; echo $ return;
}

The heart of this variant lies in the function switch_to_blog() . With this feature you can scroll through all the blogs and extract the single tag cloud. , che elaborerà l'array come una singola entità. Once this is done using array_merge() merge the individual "clouds" in a single cloud to be passed to the function wp_generate_tag_cloud() , which will process the array as a single entity.

10 comments to "WordPress MU: aggregate individual blogs tag cloud"

  1. May 6, 2009 aldo:

    This file resides in what role?

  2. May 6, 2009 Giovambattista Fazioli :

    @ Aldo:

    This file resides in what role?

    riga 552 It is located in the folder wp-includes files in the category-template.php line 552 :)

  3. May 6, 2009 aldo:

    I tried replacing the code with what you wrote but it gives me error, when I have some time so I try to change it without pasting haphazardly. I wanted to get another application that uses the Sitemap of all blogs of WPMU? Do you think there is any plugin that automatically generates a sitemap for unique user blogs?

  4. May 6, 2009 Giovambattista Fazioli :

    @ Aldo:

    but it gives me error

    What kind of gives you the error and where?

  5. May 6, 2009 aldo:
     Fatal error: Call to undefined function wp_tag_cloud() 
    in /home/content/b/a/s/bastaldo/html/wp-content/themes/FREEmium/sidebar.php
    on line 28

    me from there where they should be tags

  6. May 8, 2009 Giovambattista Fazioli :

    @ Aldo: it appears that you do not have that function available! What version of WordPress do you use?

  7. November 24, 2010 BECA :

    I was very useful! : D

    thanks

  8. November 24, 2010 WP Mu: Display the tag cloud of the network | the blog was beca :

    [...] After the excellent guides found to display the posts of the various network sites, now I would like to point out how to display the tag cloud of all the blogs in the network. The author is Undolog and guides you can find on this page. [...]

  9. November 24, 2010 BECA :

    If a tag is present in n network sites, in the tag cloud are repeated n times. Do you think it might be added the tag different sites?

    Luke

  10. November 24, 2010 Giovambattista Fazioli :

    @ BECA: quite possible, indeed. As you can see the loop of the function, the tags are extracted for each blog. So it may well happen that the same tag is present in one or more blogs. Obviously, this redundancy is only apparent because the tags (those tags) link to different contexts and content.
    What you could do is to improve function. For example, if the tag "Apple" is present on several blogs, output it would be good all the times it appears, however, indicating that belongs to different blogs. The ideal is to have an indication of how "Apple (blog name)" ...
    non combini pasticci! In practice the loop for each draw should create a list of tags-tags blog, check if there are duplicates in that case and output it in the form "tags (blog name)" ... so that array_merge ( ) do not mess!

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA