Displaying the most recently used tags

Sure, just feed your tag list to wp_generate_tag_cloud:

$found_tags = $final_tags = $id_records = array();

// get last 10 posts
$last_posts = get_posts('numberposts=10');

// gather tags
foreach($last_posts as $post)
  $found_tags = array_merge($found_tags, wp_get_post_tags($post->ID));

// prepare final tags for the cloud
foreach($found_tags as $tag){

  // ignore duplicates
  if(in_array($tag->term_id, $id_records))
    continue;

  // track ids...
  $id_records[] = $tag->term_id;

  // generate links
  $tag->link = get_tag_link($tag);

  // keep it
  $final_tags[] = $tag;
}

// feed to the cloud
print wp_generate_tag_cloud($final_tags);

You might want to cache this, because it makes quite a few queries

Leave a Comment