分类术语的视图和节点数


31

如何在视图中显示分类术语的节点计数值?并按照节点数的降序对结果列表进行排序。


2
youtube上的视频在这里很好地说明过https://www.youtube.com/watch?v=w22Utjm-chs
wranvaud

Answers:


41
  1. 创建分类视图
  2. 在关系中添加节点组
  3. 添加术语名称和节点nid字段以显示
  4. 在“其他”部分启用聚合(使用聚合:是)
  5. 单击“字段设置”图标,选择组类型“计数”。

找到对我有用的视图导出。

$view = new view;
$view->name = 'term_node_count';
$view->description = 'Displays node count values for terms';
$view->tag = '';
$view->base_table = 'taxonomy_term_data';
$view->human_name = 'term_node_count';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Defaults */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->display->display_options['use_ajax'] = TRUE;
$handler->display->display_options['group_by'] = TRUE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '100';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['pager']['options']['id'] = '0';
$handler->display->display_options['pager']['options']['expose']['items_per_page_options_all'] = 0;
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'name' => 'name',
  'nid' => 'nid',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'name' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
  'nid' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
  ),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
/* Relationship: Taxonomy: Node */
$handler->display->display_options['relationships']['nid']['id'] = 'nid';
$handler->display->display_options['relationships']['nid']['table'] = 'taxonomy_index';
$handler->display->display_options['relationships']['nid']['field'] = 'nid';
$handler->display->display_options['relationships']['nid']['required'] = 0;
/* Field: Taxonomy: Term */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'taxonomy_term_data';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = 1;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['link_to_taxonomy'] = 1;
/* Field: Node: Nid */
$handler->display->display_options['fields']['nid']['id'] = 'nid';
$handler->display->display_options['fields']['nid']['table'] = 'node';
$handler->display->display_options['fields']['nid']['field'] = 'nid';
$handler->display->display_options['fields']['nid']['relationship'] = 'nid';
$handler->display->display_options['fields']['nid']['group_type'] = 'count';
$handler->display->display_options['fields']['nid']['label'] = 'Count';
$handler->display->display_options['fields']['nid']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['nid']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['nid']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nid']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nid']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nid']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nid']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nid']['alter']['html'] = 0;
$handler->display->display_options['fields']['nid']['element_label_colon'] = 1;
$handler->display->display_options['fields']['nid']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nid']['hide_empty'] = 0;
$handler->display->display_options['fields']['nid']['empty_zero'] = 0;
$handler->display->display_options['fields']['nid']['link_to_node'] = 1;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block_1');
$translatables['term_node_count'] = array(
  t('Defaults'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort By'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('node'),
  t('Term'),
  t('Count'),
  t('Block'),
);

如果您想获取附加到实际节点上的术语的节点数怎么办?
Temaruk 2011年

23

先前的所有答案都非常有帮助。

我想要一个表,这样我就可以让用户按术语或按计数排序。

为此,我:

  1. 关系>分类术语:带有术语的内容
  2. 使用汇总:是
  3. 字段>内容:Nid
  4. Nid的汇总类型=计数DISTINCT

缺少的是如何使两个字段在线显示。为此,您需要转到“格式”->“显示”->“设置”,然后将它们都作为嵌入式项目选中。
科兰2013年

12

要正确获取分类术语的分类节点数,您需要执行以下操作:

  1. 在“字段”中:添加分类术语:名称
  2. 在关系中,添加一个分类术语:带有术语的内容
  3. 分类术语添加一个上下文过滤器:名称

    3a。选择“显示摘要”

    3b。选择“显示带有链接的记录计数”。如果希望分类法页面正确链接,还请设置基本路径。


5

关键是您必须确保已选中视图高级选项中的“聚合”复选框。


这可以更好地编辑其他人的答案(或者您可以编写更完整的答案)。
michaelmcandrew

4

为分类法术语添加一个参数(在最新的“视图”中重命名为“上下文过滤器”),然后选择“显示摘要”。然后,选择显示“记录数”。


我有意见7.x-3.0-alpha1。“上下文过滤器”在哪里。
ya.teck 2011年

然后将其标记为“参数”。但是,您可能应该只升级到最新版本。
tim.plunkett 2011年

3.0-alpha1是drupal 7的最新版本。您是说要升级到dev版本?
ya.teck 2011年

2
alpha1已于1月6日过时。这个周末应该有一个alpha2,但是可以,请使用dev。
tim.plunkett 2011年

查看3.0-rc1。像您在上面发布的那样尝试过,但我仅获得例如:类别(1),猫(1)。尽管我在术语内部有很多节点,但每个地方都接近1分类法术语。怎么了?
亚历山大·金
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.