Custom Tag Cloud – Problems with duplicate tags
-
Hello and good day everyone.
I wrote a custom tag cloud for my WordPress multisite with the help of code references available online.
Let me show you guys the basic structure of my code…<?php $arr_tags = array(); $rows = $wpdb->get_results( $wpdb->prepare( "SELECT blog_id from $wpdb->blogs WHERE public = %s AND archived = %s AND mature = %s AND spam = %s AND deleted = %s",'1','0','0','0','0' ) ); if(!empty($rows)){ $tags_count = 0; foreach ( $rows as $row ) { switch_to_blog($row->blog_id); $arrgs = new WP_query(array( 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post' )); while($arrgs->have_posts()){ $arrgs->the_post(); $posttags = get_the_tags(get_the_ID()); if ($posttags) { foreach($posttags as $tag) { $tag_list[$tags_count++] = array($tag->name, $tag->count); $tags_count++; } } } } echo '<div class="tag_cloud">'; $tag_posts_temp=""; $newArr = array(); foreach ($tag_list as $val) { $newArr[$val[0]] = $val; } $tag_list2 = array_values($newArr); for($x=0;$x<count($tag_list2);$x++){ $y=0; if($tag_list2[$x][$y] != $tag_posts_temp){ echo $tag_list2[$x][$y] . '(' . $tag_list2[$x][$y+1] . ') '; } $tag_posts_temp = $tag_list2[$x][$y]; } echo '</div>'; } ?>
The code works but I’m having problems with the possibility of having identical tags from the different subsites. :/ Basically, I want the duplicate tags to be unified, while also their values being added. So if there are two identical [monitor] tags but have different post counts; [2] and [5], I want them to be unified into [monitor][7].
Can anyone tell me how I can solve this little problem of mine? Thanks~
Viewing 12 replies - 1 through 12 (of 12 total)
Viewing 12 replies - 1 through 12 (of 12 total)
- The topic ‘Custom Tag Cloud – Problems with duplicate tags’ is closed to new replies.