Drupal Views - 按多个分类术语过滤
Posted
技术标签:
【中文标题】Drupal Views - 按多个分类术语过滤【英文标题】:Drupal Views- Filtering by multiple taxonomy terms 【发布时间】:2011-09-23 16:07:06 【问题描述】:我设置了一个视图来显示特色文章节点。对于每个节点,有 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);
【问题讨论】:
【参考方案1】:希望您有一个节点,其中包含两个词汇表中的术语.. 从导出的角度很难解决它.. 您可以做的是提供 sql 查询是哪个视图正在生成检查它或将其发布到这里..
【讨论】:
将查询添加到我的原始帖子中。干杯 是的,我有 3 个带有“home”一词的文章节点,其中 2 个也带有“yes”一词以上是关于Drupal Views - 按多个分类术语过滤的主要内容,如果未能解决你的问题,请参考以下文章