Tuesday 15 January 2013

php - make a wordpress tag cloud of an specific category link to a list of articles of that category & tag -



php - make a wordpress tag cloud of an specific category link to a list of articles of that category & tag -

i need show tag cloud of tags of particular category, i'm using function retrieve tags:

function tags_by_cat($cat_id) { $custom_query = new wp_query("posts_per_page=-1&cat={$cat_id}"); if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post(); $posttags = get_the_tags(); if ($posttags) { foreach($posttags $tag) { $all_tags[] = $tag->term_id; } } endwhile; endif; $tags_arr = array_unique($all_tags); $tags_str = implode(",", $tags_arr); homecoming $tags_str; }

and generate tag cloud in template, illustration category 33:

wp_tag_cloud( array('smallest'=>8,'largest'=>22,'include'=>tags_by_cat(33)));

the problem while works fine, every tag of cloud links list of articles containing tag, need have list filtered original category. wordpress can (i.e. http://www.website.com/?cat=33&tag=computing) can't find how introduce url parameter in urls of cloud. i'm using post name permalinks, makes things more complicated.

is there parameter want or maybe can kind of hook? going recreate own wp_tag_cloud i'm not sure of begin

well i've created hook seems work properly, may have same problem:

add_filter ( 'wp_tag_cloud', 'tag_cloud_add_cat' ); function tag_cloud_add_cat( $taglinks ) { if (is_category()) { $category = get_category( get_query_var( 'cat' ) ); $current_cat_slug = $category->slug; $tags = explode('</a>', $taglinks); $regex = "#(.*href=\')(.*)(' class.*)#e"; foreach( $tags $tag ) { $varin=strpos($tag,"?")!==false?'&':'?'; $tagres[] = preg_replace($regex, "'$1$2{$varin}category_name={$current_cat_slug}$3'", $tag ); } $taglinks = implode('</a>', $tagres); } homecoming $taglinks; }

php wordpress tag-cloud

No comments:

Post a Comment