Приветстсвую друзья, за работой абсолютно не когда было продолжить с постами на блоге. Сегодня я решил исправиться. Данный снипет кода поможет Вам отобразить облако тегов на Вашем сайте под управлением CMS WordPress. Прежде всего хочется сказать спасибо автору, и так же отмечу что данный снипет кода не мой а взят здесь: https://wordpress.stackexchange.com/questions/289393/display-tags-cloud-from-a-specific-category-id-with-a-shortcode
function tag_cloud_shortcode($atts) {
extract(shortcode_atts(array(
'cat' => ''
), $atts));
$query_args = array( 'cat' => $atts, 'posts_per_page' => -1 );
$custom_query = new WP_Query( $query_args );
if ($custom_query->have_posts()) :
while ($custom_query->have_posts()) : $custom_query->the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags[] = $tag->term_id;
}
}
endwhile;
endif;
$tags_arr = array_unique($all_tags);
$tags_str = implode(",", $tags_arr);
$args = array(
'echo' => false,
'smallest' => 10,
'largest' => 10,
'unit' => 'px',
'number' => 0,
'format' => 'flat',
'order' => 'count',
'include' => $tags_str
);
return wp_tag_cloud($args);
}
add_shortcode( 'tagscloud', 'tag_cloud_shortcode' );
Для отображения используем шорт код:
[tagscloud]
Так же Вы можете использовать этот шорткод с несколькими категориями указывая их id:
[tagscloud cat=3,5]