views:

129

answers:

4

Hello,

I've been searching for quite a while now to find a way to limit wordpress tags by date and order them by the amount of times they appeared in the selected timeframe. But I've been rather unsuccesful.

What I'm trying to achieve is something like the trending topics on Twitter. But in this case, 'trending tags'. By default the wordpress tagcloud displays the most popular tags of all time. Which makes no sense in my case, since I want to track current trends.

Ideally it would be something like:

Most popular tags of today

  • Obama (18 mentions)
  • New York (15 mentions)
  • Iron Man (11 mentions)
  • Robin Hood (7 mentions)

And then multiplied for 'most popular this week' and 'most popular this month'. Does anyone know of a way to achieve this?

A: 

I'm pretty sure that Tags does not have timestamps - perhaps you could do a search for posts with specific tags for a certain timeperiod?

stffn
They indeed don't have timestamps. However since they are related to posts, and posts do have a timestamp, my thought was that it should be possible to retrieve those timestamps. Your reply got me thinking though. Wouldn't it be easiest to just add a timestamp table to tags?
Nordin
A: 

There are some popular tag plugins and widgets: WordPress › WordPress Plugins

songdogtech
Thanks for your reply, but I've checked them all, and none of them does limit tags by date. They either limit it by views or comments and that's not what I'm looking for. There was one plugin called 'recent tags' that came close, however that one was written for wp 2.6. I gave it a try though and it stopped working after a day.
Nordin
+1  A: 

Okay, so what I think you probably want is to do this for say, the last 50 posts.

Loop over the last n posts, extract the term_id of each tag for each post, then pass that string into the include argument of wp_tag_cloud();

$how_many_posts = 50;
$args = array(
    'posts_per_page' => $how_many_posts,
    'orderby' => 'date',
    'order' => 'DESC',
);
// get the last $how_many_posts, which we will loop over
// and gather the tags of
query_posts($args);
//
$temp_ids = array();
while (have_posts()) : the_post(); 
    // get tags for each post
    $posttags = get_the_tags()
    if ($posttags) {
        foreach($posttags as $tag) {
            // store each tag id value
            $temp_ids[] = $tag->term_id;
        }
    }
endwhile;
// we're done with that loop, so we need to reset the query now
wp_reset_query();
$id_string = implode(',', array_unique($temp_ids));
// These are the params I use, you'll want to adjust the args
// to suit the look you want    
$args = array(
    'smallest'  => 10, 
    'largest'   => 30,
    'unit'      => 'px', 
    'number'    => 150,  
    'format'    => 'flat',
    'separator' => "\n",
    'orderby'   => 'count', 
    'order'     => 'DESC',
    'include'   => $id_string,  // only include stored ids
    'link'      => 'view', 
    'echo'      => true,

);
wp_tag_cloud( $args );
artlung
probably the only way to do this given how tags are stored, but will become really slow as the number of post grows...
Kasumi
A: 

I think you can look at some of the plugins and see if your have a plugin like what you need

Matt