Drupal 视图 - 按多个分类术语过滤

发布于 2024-12-06 05:22:45 字数 8535 浏览 5 评论 0原文

我设置了一个视图来显示特色文章节点。对于每个节点,有 2 个分类词汇可供使用。第一个是“精选”,带有“是”一词;第二个是带有术语的“部分”:主页、信息、博客等。如果节点具有术语“是”(特色词汇)和术语“博客”(部分词汇),那么如果您要浏览到domain.com/blog,那么您会查看该特色内容。

视图设置为接受 url 中的第一个参数,以确定您正在查看网站的哪个部分(视图参数:分类术语)。这按预期工作。

最后,我按节点类型(文章)进行过滤,然后按分类词汇(精选)进行过滤,这是我的视图无法返回内容的地方。如果我删除分类词汇过滤器,尽管它显示所有文章节点,但它会正确显示每个部分。

问题可能是参数和过滤器是不同的分类词汇吗?

这是 SQL 查询:

    SELECT node.nid AS nid,
    node.type AS node_type,
    node.vid AS node_vid,
    node_data_field_article_images.field_article_images_data AS node_data_field_article_images_field_article_images_data,
    node.title AS node_title,
    node.created AS node_created
    FROM node node 
    LEFT JOIN content_field_article_images node_data_field_article_images ON node.vid = node_data_field_article_images.vid
    LEFT JOIN term_node term_node ON node.vid = term_node.vid
    LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
    WHERE (node.status <> 0) AND (node.type in ('article')) AND (node_data_field_article_images.field_article_images_list <> 0) AND (term_data.vid in ('20')) AND (term_data.name = 'home')
    ORDER BY node_created DESC

这是我的观点:

  $view = new view;
  $view->name = 'marquee_slideshow_dev';
  $view->description = 'Marquee on homepage and landing pages';
  $view->tag = '';
  $view->view_php = '';
  $view->base_table = 'node';
  $view->is_cacheable = FALSE;
  $view->api_version = 2;
  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  $handler = $view->new_display('default', 'Defaults', 'default');
  $handler->override_option('fields', array(
    'title' => array(
      'label' => '',
      'alter' => array(
        'alter_text' => 0,
        'text' => '',
        'make_link' => 0,
        'path' => '',
        'link_class' => '',
        'alt' => '',
        'prefix' => '',
        'suffix' => '',
        'target' => '',
        'help' => '',
        'trim' => 0,
        'max_length' => '',
        'word_boundary' => 1,
        'ellipsis' => 1,
        'html' => 0,
        'strip_tags' => 0,
      ),
      'empty' => '',
      'hide_empty' => 0,
      'empty_zero' => 0,
      'link_to_node' => 0,
      'exclude' => 0,
      'id' => 'title',
      'table' => 'node',
      'field' => 'title',
      'relationship' => 'none',
      'override' => array(
        'button' => 'Override',
      ),
    ),
  ));
  $handler->override_option('sorts', array(
    'created' => array(
      'order' => 'DESC',
      'granularity' => 'second',
      'id' => 'created',
      'table' => 'node',
      'field' => 'created',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('arguments', array(
    'name' => array(
      'default_action' => 'default',
      'style_plugin' => 'default_summary',
      'style_options' => array(),
      'wildcard' => 'all',
      'wildcard_substitution' => 'All',
      'title' => '',
      'breadcrumb' => '',
      'default_argument_type' => 'php',
      'default_argument' => '',
      'validate_type' => 'none',
      'validate_fail' => 'not found',
      'glossary' => 0,
      'limit' => '0',
      'case' => 'lower',
      'path_case' => 'lower',
      'transform_dash' => 1,
      'add_table' => 0,
      'require_value' => 0,
      'id' => 'name',
      'table' => 'term_data',
      'field' => 'name',
      'validate_user_argument_type' => 'uid',
      'validate_user_roles' => array(
        '2' => 0,
        '7' => 0,
        '8' => 0,
        '4' => 0,
        '6' => 0,
        '5' => 0,
      ),
      'relationship' => 'none',
      'default_options_div_prefix' => '',
      'default_argument_fixed' => '',
      'default_argument_user' => 0,
      'default_argument_image_size' => '_original',
      'default_argument_php' => '$path = explode(\'/\', drupal_get_path_alias($_GET[\'q\']));
  $is_front = $_GET[\'q\'] == \'<front>\' || $_GET[\'q\'] == variable_get(\'site_frontpage\', \'<front>\');
  $arg0 = arg(0);

  if ($is_front) {
    return \'home\';
  } else if ($arg0 = \'node\' && arg(1) != \'add\' && arg(2) != \'edit\' && arg(2) != \'delete\' && $path[0] != \'\') {
    return $path[0];
  }
  ',
      'validate_argument_node_type' => array(
        'activitystream' => 0,
        'image' => 0,
        'contenttab' => 0,
        'content_about_fedex_content_page' => 0,
        'content_about_fedex_home_page' => 0,
        'content_about_fedex_landing_page' => 0,
        'content_access_article' => 0,
        'content_access_article_index' => 0,
        'content_access_content_page' => 0,
        'content_access_landing_page' => 0,
        'content_block' => 0,
        'content_case_study' => 0,
        'content_document' => 0,
        'content_event' => 0,
        'content_executive_viewpoint' => 0,
        'content_feature' => 0,
        'content_fedex_fact' => 0,
        'content_fedex_video_page' => 0,
        'content_great_place_to_work' => 0,
        'content_location' => 0,
        'content_opco_overview' => 0,
        'content_our_commitment_content_p' => 0,
        'content_our_commitment_landing_p' => 0,
        'content_region_overview' => 0,
        'content_resources' => 0,
        'content_sag' => 0,
        'content_small_business' => 0,
        'page' => 0,
        'slideshow_image' => 0,
        'story' => 0,
      ),
      'validate_argument_node_access' => 0,
      'validate_argument_nid_type' => 'nid',
      'validate_argument_vocabulary' => array(
        '14' => 0,
        '18' => 0,
        '17' => 0,
        '11' => 0,
        '10' => 0,
        '15' => 0,
        '9' => 0,
        '3' => 0,
        '16' => 0,
        '8' => 0,
        '5' => 0,
        '2' => 0,
        '7' => 0,
        '19' => 0,
        '1' => 0,
        '12' => 0,
        '13' => 0,
      ),
      'validate_argument_type' => 'tid',
      'validate_argument_transform' => 0,
      'validate_user_restrict_roles' => 0,
      'image_size' => array(
        '_original' => '_original',
        'thumbnail' => 'thumbnail',
        'preview' => 'preview',
        'icon' => 'icon',
      ),
      'validate_argument_php' => '',
      'override' => array(
        'button' => 'Override',
      ),
    ),
  ));
  $handler->override_option('filters', array(
    'status' => array(
      'operator' => '=',
      'value' => '1',
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'status',
      'table' => 'node',
      'field' => 'status',
      'relationship' => 'none',
    ),
    'type' => array(
      'operator' => 'in',
      'value' => array(
        'article' => 'article',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'type',
      'table' => 'node',
      'field' => 'type',
      'relationship' => 'none',
    ),
    'vid' => array(
      'operator' => 'in',
      'value' => array(
        '20' => '20',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'vid',
      'table' => 'term_data',
      'field' => 'vid',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('access', array(
    'type' => 'none',
  ));
  $handler->override_option('cache', array(
    'type' => 'none',
  ));
  $handler->override_option('empty_format', '3');
  $handler->override_option('items_per_page', 0);
  $handler->override_option('use_pager', 'mini');
  $handler->override_option('distinct', 0);
  $handler->override_option('style_options', array(
    'grouping' => '',
  ));
  $handler = $view->new_display('block', 'Home Page', 'block_1');
  $handler->override_option('block_description', '');
  $handler->override_option('block_caching', -1);

I have a View set up to display featured Article nodes. For each node there are 2 taxonomy vocabs to use. The first is 'Featured' with a term 'Yes'; the second is 'Section' with terms: Home, Info, Blog etc. If a node has the term Yes (Featured vocab) and the term Blog (Section vocab) then if you were to browse to domain.com/blog then you would see that featured content.

The view is set up to accept the first argument in the url to determine which section of the site you are viewing (Views argument: Taxonomy term). This works as expected.

Lastly, I am filtering by node type (Article) and then the taxonomy vocab (Featured) which is where my view is failing to return content. If I remove the taxonomy vocab filter it displays correctly for each section although it is displaying all Article nodes.

Could the issue be that the argument and filter are different taxonomy vocabs?

Here's the SQL query:

    SELECT node.nid AS nid,
    node.type AS node_type,
    node.vid AS node_vid,
    node_data_field_article_images.field_article_images_data AS node_data_field_article_images_field_article_images_data,
    node.title AS node_title,
    node.created AS node_created
    FROM node node 
    LEFT JOIN content_field_article_images node_data_field_article_images ON node.vid = node_data_field_article_images.vid
    LEFT JOIN term_node term_node ON node.vid = term_node.vid
    LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
    WHERE (node.status <> 0) AND (node.type in ('article')) AND (node_data_field_article_images.field_article_images_list <> 0) AND (term_data.vid in ('20')) AND (term_data.name = 'home')
    ORDER BY node_created DESC

Here's my view:

  $view = new view;
  $view->name = 'marquee_slideshow_dev';
  $view->description = 'Marquee on homepage and landing pages';
  $view->tag = '';
  $view->view_php = '';
  $view->base_table = 'node';
  $view->is_cacheable = FALSE;
  $view->api_version = 2;
  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
  $handler = $view->new_display('default', 'Defaults', 'default');
  $handler->override_option('fields', array(
    'title' => array(
      'label' => '',
      'alter' => array(
        'alter_text' => 0,
        'text' => '',
        'make_link' => 0,
        'path' => '',
        'link_class' => '',
        'alt' => '',
        'prefix' => '',
        'suffix' => '',
        'target' => '',
        'help' => '',
        'trim' => 0,
        'max_length' => '',
        'word_boundary' => 1,
        'ellipsis' => 1,
        'html' => 0,
        'strip_tags' => 0,
      ),
      'empty' => '',
      'hide_empty' => 0,
      'empty_zero' => 0,
      'link_to_node' => 0,
      'exclude' => 0,
      'id' => 'title',
      'table' => 'node',
      'field' => 'title',
      'relationship' => 'none',
      'override' => array(
        'button' => 'Override',
      ),
    ),
  ));
  $handler->override_option('sorts', array(
    'created' => array(
      'order' => 'DESC',
      'granularity' => 'second',
      'id' => 'created',
      'table' => 'node',
      'field' => 'created',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('arguments', array(
    'name' => array(
      'default_action' => 'default',
      'style_plugin' => 'default_summary',
      'style_options' => array(),
      'wildcard' => 'all',
      'wildcard_substitution' => 'All',
      'title' => '',
      'breadcrumb' => '',
      'default_argument_type' => 'php',
      'default_argument' => '',
      'validate_type' => 'none',
      'validate_fail' => 'not found',
      'glossary' => 0,
      'limit' => '0',
      'case' => 'lower',
      'path_case' => 'lower',
      'transform_dash' => 1,
      'add_table' => 0,
      'require_value' => 0,
      'id' => 'name',
      'table' => 'term_data',
      'field' => 'name',
      'validate_user_argument_type' => 'uid',
      'validate_user_roles' => array(
        '2' => 0,
        '7' => 0,
        '8' => 0,
        '4' => 0,
        '6' => 0,
        '5' => 0,
      ),
      'relationship' => 'none',
      'default_options_div_prefix' => '',
      'default_argument_fixed' => '',
      'default_argument_user' => 0,
      'default_argument_image_size' => '_original',
      'default_argument_php' => '$path = explode(\'/\', drupal_get_path_alias($_GET[\'q\']));
  $is_front = $_GET[\'q\'] == \'<front>\' || $_GET[\'q\'] == variable_get(\'site_frontpage\', \'<front>\');
  $arg0 = arg(0);

  if ($is_front) {
    return \'home\';
  } else if ($arg0 = \'node\' && arg(1) != \'add\' && arg(2) != \'edit\' && arg(2) != \'delete\' && $path[0] != \'\') {
    return $path[0];
  }
  ',
      'validate_argument_node_type' => array(
        'activitystream' => 0,
        'image' => 0,
        'contenttab' => 0,
        'content_about_fedex_content_page' => 0,
        'content_about_fedex_home_page' => 0,
        'content_about_fedex_landing_page' => 0,
        'content_access_article' => 0,
        'content_access_article_index' => 0,
        'content_access_content_page' => 0,
        'content_access_landing_page' => 0,
        'content_block' => 0,
        'content_case_study' => 0,
        'content_document' => 0,
        'content_event' => 0,
        'content_executive_viewpoint' => 0,
        'content_feature' => 0,
        'content_fedex_fact' => 0,
        'content_fedex_video_page' => 0,
        'content_great_place_to_work' => 0,
        'content_location' => 0,
        'content_opco_overview' => 0,
        'content_our_commitment_content_p' => 0,
        'content_our_commitment_landing_p' => 0,
        'content_region_overview' => 0,
        'content_resources' => 0,
        'content_sag' => 0,
        'content_small_business' => 0,
        'page' => 0,
        'slideshow_image' => 0,
        'story' => 0,
      ),
      'validate_argument_node_access' => 0,
      'validate_argument_nid_type' => 'nid',
      'validate_argument_vocabulary' => array(
        '14' => 0,
        '18' => 0,
        '17' => 0,
        '11' => 0,
        '10' => 0,
        '15' => 0,
        '9' => 0,
        '3' => 0,
        '16' => 0,
        '8' => 0,
        '5' => 0,
        '2' => 0,
        '7' => 0,
        '19' => 0,
        '1' => 0,
        '12' => 0,
        '13' => 0,
      ),
      'validate_argument_type' => 'tid',
      'validate_argument_transform' => 0,
      'validate_user_restrict_roles' => 0,
      'image_size' => array(
        '_original' => '_original',
        'thumbnail' => 'thumbnail',
        'preview' => 'preview',
        'icon' => 'icon',
      ),
      'validate_argument_php' => '',
      'override' => array(
        'button' => 'Override',
      ),
    ),
  ));
  $handler->override_option('filters', array(
    'status' => array(
      'operator' => '=',
      'value' => '1',
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'status',
      'table' => 'node',
      'field' => 'status',
      'relationship' => 'none',
    ),
    'type' => array(
      'operator' => 'in',
      'value' => array(
        'article' => 'article',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'type',
      'table' => 'node',
      'field' => 'type',
      'relationship' => 'none',
    ),
    'vid' => array(
      'operator' => 'in',
      'value' => array(
        '20' => '20',
      ),
      'group' => '0',
      'exposed' => FALSE,
      'expose' => array(
        'operator' => FALSE,
        'label' => '',
      ),
      'id' => 'vid',
      'table' => 'term_data',
      'field' => 'vid',
      'relationship' => 'none',
    ),
  ));
  $handler->override_option('access', array(
    'type' => 'none',
  ));
  $handler->override_option('cache', array(
    'type' => 'none',
  ));
  $handler->override_option('empty_format', '3');
  $handler->override_option('items_per_page', 0);
  $handler->override_option('use_pager', 'mini');
  $handler->override_option('distinct', 0);
  $handler->override_option('style_options', array(
    'grouping' => '',
  ));
  $handler = $view->new_display('block', 'Home Page', 'block_1');
  $handler->override_option('block_description', '');
  $handler->override_option('block_caching', -1);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-12-13 05:22:45

希望你有一个节点,其中包含词汇表中的术语..
从导出的角度来看很难解决它..
你可以做的是提供视图正在生成的sql查询,检查它或将其发布到这里..

hope you have a node which has terms from both the vocabulary ..
its difficult to solve it from exported view..
what you can do is provide the sql query which view is generating check it or post it over here..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文