Answers:
最后,我创建了自己的自定义模块,以从数据库中获取术语并将其分组/排序。
请注意,我已经稍微修改了以下代码以便发布,并且尚未测试修改后的版本。还值得注意的是它是为使用PostgreSQL的站点编写的,但它应与MySQL一起使用。
/**
* Implements hook_block_info().
*/
function MYMODULE_block_info() {
$blocks['poptags'] = array(
'info' => t('Most Popular Tags'),
'cache' => DRUPAL_NO_CACHE
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function MYMODULE_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'poptags':
$block['subject'] = t('Most Popular Tags');
$block['content'] = _MYMODULE_popular_terms();
break;
}
return $block;
}
function _MYMODULE_popular_terms() {
$vocabId = 1;
$links = array();
$results = db_query_range('SELECT taxonomy_term_data.tid, taxonomy_term_data.name, count(taxonomy_term_data.tid) AS times_used FROM taxonomy_term_data INNER JOIN taxonomy_index ON taxonomy_term_data.tid = taxonomy_index.tid WHERE taxonomy_term_data.vid = :vid GROUP BY taxonomy_term_data.tid, taxonomy_term_data.name ORDER BY times_used DESC', 0, 10, array(':vid' => $vocabId));
foreach ($results as $term) {
$links['term-link-' . db_escape_field($term->name)] = array('title' => $term->name, 'href' => drupal_get_path_alias('taxonomy/term/' . $term->tid));
}
return theme('links', array('links' => $links, 'attributes' => array('class' => 'term-links')));
}
不要忘记更改MYMODULE
模块名称。最后$vocabId = 1
,将_MYMODULE_popular_terms
函数中的行更改为要列出其词汇的词汇的vid(词汇ID)。
请注意,这仅适用于Drupal 7,尽管将其移植到Drupal 6并不需要很多。
您可以从tagadelic中提取数据。
$output = '';
$vids = array(1, 2, 3, 4); #Taxonomy vocabulary-ids you want to be included.
$top_tags = tagadelic_get_weighted_tags($vids, 6, 10);
foreach ($terms as $term) {
$weight = $term->weight;
$output .= l($term->name, drupal_get_path_alias('taxonomy/term/' . $term->tid), array(
'attributes' => array(
'class' => array("tagadelic", "level$weight"),
'rel' => 'tag',
'title' => $term->description,
)
)
) . " \n";
}
return $output;
唯一的缺点是,tagadelic增加了一些较小的开销来计算“重量”,通常会显示标签的大小,您将不会使用它们。
好处是您可以免费获得缓存。