如果有多个过滤器,如何显示仅使用一个术语ID标记的结果(How to display results tagged with just one term ID when there are multi

编程入门 行业动态 更新时间:2024-10-12 03:27:06
如果有多个过滤器,如何显示仅使用一个术语ID标记的结果(How to display results tagged with just one term ID when there are multiple filters)

我在Drupal 7中有一个博客,并使用Views来显示字段。 我在侧栏上显示了两组标签:

1) SHAPES Triangle Square Rectangle 2) COLOR Red Blue Green

我通过Structure> Taxonomy> Vocabulary> Add Term创建了2组标签

对于View,我使用两个公开的过滤器创建了一个View(类似于本教程中的内容 )

视图:

Path: '/blog/tag' Filter Criteria: 1) 'Content: Shape (exposed)' Exposed form in Block: 'Yes' Filter identifier: 'shape_id' 2) 'Content: Color (exposed)' Exposed form in Block: 'Yes' Filter identifier: 'color_id' Exposed form style: BEF

公开的过滤器设置为Structure> Blocks中的相应块区域。

如果我点击“三角形”,则只显示标有“三角形”的博客文章。 然后,如果我点击“红色”,则只显示标有“红色”的帖子。

当我点击这些条款时,看起来正在显示正确的博客文章。 该URL附加了两个词汇表中的ID,但我似乎无法显示正确的组合。

单击“三角形”时所需的URL:'/ blog / tag /?shape_id = 1&color_id = All'

单击“红色”时所需的URL:'/ blog / tag /?shape_id = All&color_id = 1'

因此,基本上结果应该显示标记有一个术语ID的项目。

然而,它目前的工作方式是,如果我点击“三角形”,然后“红色”,“三角形”和“红色”都有“选定”类(都是粗体),网址为:'/ blog /标签/?shape_id = 1&COLOR_ID = 1'

我能够获得所需URL的唯一方法是显示“-Any-”选项。 但是,我使用的用例是在标签列表中没有列出“-Any-”。

如果没有在术语列表中列出'-Any-',这是否可能? 我之前从未使用过多个曝光过滤器,所以任何指导都会很棒,因为我已经研究了近一周了。 我在另一篇文章中读到,上下文过滤器允许我创建单独的路径别名,这些路径别名是干净的URL,但我还没有成功地做到这一点。

任何帮助将不胜感激。 感谢您的时间。

I have a blog in Drupal 7 and used Views to display the fields. I have 2 sets of tags displayed on the sidebar:

1) SHAPES Triangle Square Rectangle 2) COLOR Red Blue Green

I created the 2 groups of tags via Structure > Taxonomy > Vocabulary > Add Term

For the View, I created one View with two exposed filters (similar to what was done in this tutorial)

VIEW:

Path: '/blog/tag' Filter Criteria: 1) 'Content: Shape (exposed)' Exposed form in Block: 'Yes' Filter identifier: 'shape_id' 2) 'Content: Color (exposed)' Exposed form in Block: 'Yes' Filter identifier: 'color_id' Exposed form style: BEF

The exposed filters are set to the appropriate block region in Structure > Blocks.

If I click 'triangle', only blog posts tagged with 'triangle' should be displayed. Then if I click 'red', only posts tagged with 'red' should be displayed.

It looks like the correct blog posts are being displayed when I click on the terms. The URL gets appended with IDs from both vocabularies, but I can't seem to get the right combos to display.

Desired URL when 'triangle' is clicked: '/blog/tag/?shape_id=1&color_id=All'

Desired URL when 'red' is clicked: '/blog/tag/?shape_id=All&color_id=1'

So, essentially the results should display items tagged with just one term ID.

However, how it is currently working is that if I click 'triangle', and then 'red', both 'triangle' and 'red' have the 'selected' class (are both bolded) and the url is: '/blog/tag/?shape_id=1&color_id=1'

The only way I was able to get the desired URLs is if I have the '-Any-' option displayed. However, the use case I have is to NOT have '-Any-' listed in the list of tags.

Is this even possible without '-Any-' listed in the list of terms? I have never used multiple exposed filters before, so any guidance would be great as I've researched this for almost a week now. I read in another post that contextual filters would allow me to create separate path aliases that are clean urls, but I have not been successfully able to do this.

Any help would be greatly appreciated. Thank you for your time.

最满意答案

我尝试使用分类学术语页面方法,但无法弄清楚如何正确显示字段。 显示的字段基于我的博客内容类型中的预告片。 使用暴露过滤器选项不是解决方案,因为我的用例是仅显示基于一个标签的结果。 什么对我有用:

1)向现有博客视图添加新视图

2)格式:'无格式列表'显示:'字段'

3)FIELDS:[添加您需要显示的字段]

4)FILTER CRITERIA:'内容:发布(是)'; '内容:类型(=博客)'

5)路径:'/ blog / [你的词汇名称] /%'

6)上下文过滤器:'内容:具有分类术语ID'

当过滤器值不在URL中时:'显示指定字段的所有结果'

当过滤器值在URL中或提供默认值时:选择“覆盖标题”并在输入字段中输入:'[您的词汇名称] /%1'

选择“指定验证标准”

Validator下拉菜单,选择'Taxonomy Term'

词汇表:选择合适的词汇表名称

过滤器值类型下拉列表:'术语名称转换为术语ID'

选择'将URL中的破折号转换为术语名称过滤值中的空格'

过滤器值未验证时要采取的操作:选择适合您需要的一个(在我的情况下:'显示内容“未找到结果”')

如果您需要在结果页面的标题中显示术语名称,请在同一视图中> HEADER>添加'Global:Unfiltered Text'>然后在文本区域中添加“查看[您的词汇名称]的结果/% 1"

保存视图。 由于我有多个过滤器,我克隆了上面的视图并重命名了所有内容。 所以,我最终在现有的博客视图中添加了3个额外的视图。

我以前为Taxonomy Term Paths设置了URL别名,所以我删除了这些

此外,我必须单独回到我的分类条款并删除从模式生成的URL别名

要使标题列表显示在右侧,并带有所需的URL结构/ blog / [您的词汇名称] / [您的名称],我创建了一个单独的新视图:

显示:“[你的词汇名称]”类型的“分类术语”

创建一个块

'Fields'的'未格式化列表'

字段:'分类:术语名称'>单击此按钮并取消选中“将此字段链接到其分类术语页面”。 然后展开“重写结果”部分并在链接路径中选择“将此字段输出为链接”>:'博客/ [您的词汇名称] / [名称]'(网址结构末尾的[名称]应该出现正如您在方括号中看到的那样)>选择'用短划线替换空格'>将大小写转换为'小写'>单击应用

FILTER CRITERIA:'分类词汇:机器名称(= [你的词汇名称])'

保存视图

然后在Structure> Blocks中,将块放在适当的区域中

希望这有助于某人!

I tried using the taxonomy term pages approach, but could not figure out how to get the fields displaying properly. The fields displayed were based on the teaser in my Blog content type. And using exposed filter option was not a solution since my use case was to only display results based on one tag. What worked for me:

1) Add new view to existing Blog View

2) FORMAT: 'Unformatted list' SHOW: 'Fields'

3) FIELDS: [add fields that you need displayed]

4) FILTER CRITERIA: 'Content: Published (Yes)'; 'Content: Type (= Blog)'

5) PATH: '/blog/[YOUR VOCABULARY NAME]/%'

6) CONTEXTUAL FILTERS: 'Content: Has Taxonomy Term ID'

WHEN THE FILTER VALUE IS NOT IN THE URL: 'Display all results for the specified field'

WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED: select 'Override title' and in the input field, enter: '[YOUR VOCABULARY NAME]/%1'

select 'Specify validation criteria'

Validator drop-down, select 'Taxonomy Term'

Vocabularies: select appropriate Vocabulary name

Filter value type drop-down: 'Term name converted to term ID'

select 'Transform dashes in URL to spaces in term name filter values'

Action to take if filter value does not validate: select appropriate one that works for your needs (in my case: 'Display contents of "No Results found"')

If you need to display the term name in the heading on the results page, in the same view > HEADER > Add 'Global: Unfiltered Text' > then in text area, add something like "VIEWING RESULTS FOR [YOUR VOCABULARY NAME] / %1"

Save the View. Since I had multiple filters, I cloned the above view and renamed everything. So, I ended up adding 3 additional views to my existing Blog View.

I had previously set URL aliases for Taxonomy Term Paths, so I removed these

Also, I had to go back to my Taxonomy Terms individually and delete the URL alias that was generated from the pattern

To have the list of tags displaying on the right with the desired URL structure of /blog/[YOUR VOCABULARY NAME]/[YOUR TERM NAME], I created a separate new view:

SHOW: 'Taxonomy Terms' of type '[YOUR VOCABULARY NAME]'

Create a Block

'Unformatted list' of 'Fields'

FIELDS: 'Taxonomy: Term Name' > click this and unselect 'Link this field to its taxonomy term page'. Then expand "Rewrite Results" section and select 'Output this field as a link' > in the Link path: 'blog/[YOUR VOCABULARY NAME]/[name]' (the [name] at the end of the url structure should appear as you see it with the square brackets) > select 'Replace spaces with dashes' > Transform the case to 'lower case' > click Apply

FILTER CRITERIA: 'Taxonomy vocabulary: Machine Name (= [YOUR VOCABULARY NAME])'

Save the View

Then in Structure > Blocks, place the block in the appropriate region

Hope this helps someone!

更多推荐

本文发布于:2023-08-04 03:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405344.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   过滤器   术语   标记   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!