简体   繁体   English

如何显示当前项的节点数?

[英]How to display number of nodes with current term?

I try to display my taxonomy terms through views, from my vocbulary 我尝试从我的词汇表中通过视图显示我的分类法术语

now it goes like this 现在像这样

  • term1 name term1名称
  • term1 img term1 img

I need to add count of all nodes with that term, and it will look like -> 我需要用该术语添加所有节点的数量,它看起来像->

  • term1 name term1名称
  • term1 img term1 img
  • count of all nodes with * term1 * * term1 *的所有节点数

so far, my idea was to display term id in additional field, after use preprocess function, and run SQL query to count all nodes with that term, 到目前为止,我的想法是在使用预处理功能后,在其他字段中显示术语ID ,然后运行SQL查询以计算具有该术语的所有节点,

but i think there must be a easy way, looking for ideas 但我认为必须有一种简便的方法来寻找想法

  1. Create Taxonomy Views. 创建分类视图。
  2. Add relationship to the node (in case if you want to count number of nodes). 将关系添加到节点(如果要计算节点数)。
  3. Enable grouping (Group by) (or "Use aggregation" toggle in D7, then set the "Aggregation Settings" for each field) 启用分组(“分组依据”)(或D7中的“使用聚合”切换,然后为每个字段设置“聚合设置”)
  4. In Style Settings/Format set Grouping field to 'Term ID' or 'Node ID' (depends of your query) 在“样式设置/格式”中,将“分组”字段设置为“术语ID”或“节点ID”(取决于您的查询)
  5. Add new field 'Node: NID' and set Group type to: Count 添加新字段“节点:NID”并将“组类型”设置为:“计数”

That should give you the count 那应该给你数

Ref : http://drupal.org/node/603868#comment-4421144 参考: http : //drupal.org/node/603868#comment-4421144

Here is a simple method available for the same : 这是一个适用于相同方法的简单方法:

$tid = 'Enter tid number say 5';
$nids = taxonomy_select_nodes($tid, FALSE);
// count node here
$count = count($nids);
// you can load node content here
$nodes = node_load_multiple($nids);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM