Question

I'm using a little function below to list out the post_terms. The function is outputting very specific markup for the grouping, filter, and href attributes (this is a term selector for the jQuery isotope plugin).

$terms = get_terms("post_tag");
$count = count($terms);
 if($count > 0){
    echo '<div class="option-combo tag">';
    echo '<h4>Post Tags</h4>';
    echo '<ul class="filter option-set floated clearfix">';
    echo '<li><a href="#filter-tag-any" data=filter="" data-group="tag" class="selected">any</a>';
    foreach ($terms as $term) {
        echo '<li><a href="#filter-tag-'.$term->slug.'" data-group="tag" data-filter=".tag-'.$term->slug.'">'.$term->name.'</a>';        
    }
    echo '</ul>';
    echo '</div>';
 }

Question:

Given the requirements above where each term has it's own custom href, data-group, data-filter, how would I go about changing this list format into a tag cloud with my requirements?

(an ordered list of terms is way to long for use within a sidebar, hence a tag cloud would work much better when using terms as a selector)

I did look through the codex, but didn't see any examples on how to modify the output of the tag cloud.

thanks

Was it helpful?

Solution

This is how the links are created in wp_generate_tag_cloud (wp-includes/category-template.php)

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</a>";
}

There seems not to be a way to do what you need. Maybe copying all wp_generate_tag_cloud and modifying it to your needs in your functions.php?

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top