带有内容计数器的分类列表

时间:2012-06-04 13:48:17

标签: drupal drupal-views drupal-taxonomy

使用Drupal 7,

我有一个内容类型:电影,

它有演员分类:Keanu Reeves,Christian Bale,Milla Jovovich等。

我想构建一个视图,其中列出了与分类术语匹配的内容计数的角色分类,例如:

Keanu Reeves (4)
Christian Bale (8)
Milla Jovovich (2)

我不确定如何构建此视图,

我设置了一个使用聚合的视图,filter:= published,content type = movie,lang = users language,

字段:COUNT(内容:演员)

似乎没有实现我的目标,请帮忙!

3 个答案:

答案 0 :(得分:2)

找不到通过视图实现的方法,这里有一个替换视图的自定义块代码。     

$vid = 3; //vocabulary id
$num_term = 8; //limit maximum terms

$query = "SELECT tid, name, count
FROM (
SELECT td.tid AS tid, name, COUNT(td.tid) AS count
FROM taxonomy_term_data AS td
JOIN taxonomy_index AS tn
  ON td.tid = tn.tid
JOIN node AS n
  ON n.nid = tn.nid
WHERE td.vid = ". $vid ."
  AND n.status = 1
GROUP BY td.tid
ORDER BY count DESC
LIMIT ". $num_term . "
) AS t
ORDER BY name ASC";

$result = db_query($query);
foreach($result as $term) {
if ($term->count > 0) {
  echo l($term->name, "taxonomy/term/$term->tid").' ('.$term->count.')'.'<br/>';
}
}

?>

答案 1 :(得分:1)

应该有办法生成您正在寻找的视图,而无需进行自定义编码。看看http://eureka.ykyuen.info/2012/01/20/drupal-7-get-number-of-nodes-of-taxonomy-term-in-views/http://dev.nodeone.se/en/the-aggregation-setting-the-emmajane-episode是否对您有所帮助。

答案 2 :(得分:0)

在Drupal 7中,可以使用Views执行此操作。无需编码或附加模块。有关食谱,请参阅How To Use Views Aggregator to Create Taxonomy Term Count Block?