Block with popular terms?

Summit - January 9, 2009 - 22:22
Project:Term Blocks
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Hi,

Would it be possible to add a block option to show popular terms (als terms which may be not hold nodes)?
Thanks a lot in advance for considering adding it.
Preferrebly on D5 and D6 :)

Greetings,
Martijn

#1

drupalina - August 8, 2009 - 03:06

Subscribing!

I'm looking for a module that would list 10 most popular tags in the last 24hours ... like we see on Twitter. Would be greatest way to keep pulse on what the community is bloging about in the last 24 hours or the last 48hours or 168hous.
I'm surprised there is no such solution in Drupal.

#2

fxarte - August 27, 2009 - 20:16

I used the Tagadelic 6.x-1.2 module to acomplish this, could not find another solution, even tried views.

in the function tagadelic_sort_tags($tags, $delta=NULL)
added an extra parameter '$delta' with default value to NULL
changed from
list($sort, $order) = explode(',', variable_get('tagadelic_sort_order', 'title,asc'));
to:
if ($delta!=NULL)

list($sort, $order) = explode(',', variable_get('tagadelic_sort_order_'.$delta, 'title,asc'));
}
else
{
list($sort, $order) = explode(',', variable_get('tagadelic_sort_order', 'title,asc'));
}
added an extra case to the switch:
    case 'count':
      usort($tags, "_tagadelic_sort_by_count");
      break;
defined the sort by count function, a callback for usort:
/**
* callback for usort, sort by count
*/
function _tagadelic_sort_by_count($a, $b) {
  return strnatcasecmp($a->count, $b->count);
}

defined a new callback for the hook_theme
/**
* theme function that renders the HTML for the tags using item_list theme function
* @ingroup themable
*/
function theme_tagadelic_list($terms) {
  $output = '';
  foreach ($terms as $term) {
    $items[]= l($term->name, taxonomy_term_path($term));
  }
  return theme('item_list',$items);
}
And it's new definition in the HOOK_theme:
'tagadelic_list' => array('arguments' => array('terms' => NULL)),

in the hook_block added code to get the extra block, wich I called popular:

First, add an extra code when $op=='view' to get the new delta, in this case 'popular_'.[term_id]
elseif (substr($delta,0,7)=='popular')
{
$tmp = split("_",$delta);
$voc = taxonomy_vocabulary_load($tmp[1]);
      $blocks['subject'] = variable_get('tagadelic_block_title_popular_'. $tmp[1], t('Popular Tags in @voc', array('@voc' => $voc->name)));
      $tags = tagadelic_get_weighted_tags(array($voc->vid), variable_get('tagadelic_levels', 6), variable_get('tagadelic_block_tags_'. $tmp[1], 12));
      $tags = tagadelic_sort_tags($tags,$delta);
      //$blocks['content'] = theme('tagadelic_weighted', $tags);//return a chunk of 12 tags
      $blocks['content'] = theme('tagadelic_list', $tags);//return a chunk of 12 tags
     // $blocks['content'] = theme('tagadelic_weighted', $tags);//return a chunk of 12 tags
}
Then in the 'list' statement:
$blocks['popular_'.$voc->vid]['info'] = variable_get('tagadelic_block_title_'. $voc->vid, t('Popular Tags in @voc', array('@voc' => $voc->name)));
    $blocks['popular_'.$voc->vid]['cache'] = BLOCK_CACHE_PER_PAGE;
In the 'configure' we add sort for each individual block, this will override the module global setting:
$options = array('weight,asc' => t('by weight, ascending'), 'weight,desc' => t('by weight, descending'), 'title,asc' => t('by title, ascending'), 'title,desc' => t('by title, descending'), 'random,none' => t('random'),'count,desc'=>'count,descending');
$form['sort_order_'.$delta] = array(
'#type' => 'radios',
'#title' => t('Tagadelic sort order'),
'#options' => $options,
'#default_value' => variable_get('tagadelic_sort_order_'. $delta, 'title,asc'),
'#description' => t('Determines the sort order of the tags on the freetagging page.'),
);
Finally in the 'save' operation, we add this extra code:
    variable_set('tagadelic_sort_order_'. $delta, $edit['sort_order_'.$delta]);

Now I have an extra block with the popular terms besides the cloud tag for each vocabulary
It's still under development but you can have a look here http://tattooclick.com/

#3

Summit - August 27, 2009 - 21:02

Could you make an add-on patch for the tagadelic module for this?
Then it is available for everyone!
Thanks for considering this.
greetings,
Martijn

#4

konrad1811 - August 29, 2009 - 22:37

Ok but what does tagadelic realy do?
I have just ran it and choose sort by weight...
It seems working like weight is a number of node the term refers to...
Maybe it's accidentaly (when I test this) but I an see no other exaplanation as weigts of taxonomy is everywhere 0.
So maybe sorting by weight (an option in tagdelic settings) is what we talk about here?

 
 

Drupal is a registered trademark of Dries Buytaert.