Display Most Popular Tags?

I got the “Most Popular Tags” wordpress plugins so I can display the tags on my site, but it displays a bunch of general tags. Is there any code I can add that will allow me to display the most popular tags on my site with the option of excluding the tags I don’t want? Or a plugin that allows this?

Related posts

Leave a Reply

3 comments

  1. The solutions I see involve writing custom queries or plugins. While you asked about a specific plugin, know that this can be done through pure WP. Here are two options:

    First, you can create a tag cloud using wp_tag_cloud and sort it by count, as such:

    $tags = wp_tag_cloud(array(
        'echo' => false,
        'orderby' => 'count',
        'order' => 'DESC'
    ));
    

    You can exclude certain tags from using the exclude parameter. You can also customize the font size output, or simply use CSS to ignore the tag cloud font sizes.

    Another option is to use get_terms, which can be used as such:

    $tags = get_terms(array(
        'taxonomy' => 'post_tag',
        'orderby' => 'count',
        'order' => 'DESC',
    ));
    

    I personally am a fan of the second, get_terms option. Like with wp_tag_cloud, you can pass a list of ids to exclude through the exclude parameter.

  2. This code will return the most used tags on the last 30 days. With a little bit of jQuery and CSS you can customize to, for example, put a large font-size on the first one and a small font-size on the last one.

    <ul id="footer-tags">
        <?php $wpdb->show_errors(); ?> 
        <?php
            global $wpdb;
            $term_ids = $wpdb->get_col("
                SELECT term_id FROM $wpdb->term_taxonomy
                INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
                INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
                WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= $wpdb->posts.post_date");
    
    if(count($term_ids) > 0){
    
      $tags = get_tags(array(
        'orderby' => 'count',
        'order'   => 'DESC',
        'number'  => 28,
        'include' => $term_ids,
      ));
    
    foreach ( (array) $tags as $tag ) {
        echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>';
    }
    }
    ?>
    </ul>
    
  3. I think the get_tags->count does not really count the tags in a range. I have implemented this solution, please let me know if this works for you:

    <?php
    global $wpdb;
    $term_ids = $wpdb->get_col("
    SELECT term_id , count(*) cont FROM $wpdb->term_taxonomy
    INNER JOIN $wpdb->term_relationships ON $wpdb->term_taxonomy.term_taxonomy_id=$wpdb->term_relationships.term_taxonomy_id
    INNER JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
    WHERE DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= $wpdb->posts.post_date AND  $wpdb->term_taxonomy.taxonomy='post_tag'
    GROUP BY term_id
    ORDER BY cont DESC
    LIMIT 5");
    
    if(count($term_ids) > 0){
       $tags = get_tags(array(
       'orderby' => 'count',
       'order'   => 'DESC',
       'number'  => 5,
       'include' => $term_ids,
    ));
    foreach ( (array) $tags as $tag ) {
       echo '<li><a href="' . get_tag_link ($tag->term_id) . '" rel="tag">' . $tag->name . '</a></li>';
    }
    }
    ?>