问题描述
我有一个Drupal网站,我发布比赛结果。我已经创建了一个内容类型,我在比赛中为1人写了结果。所以领域就像:比赛日期,球员名称,最终位置。
如果10人在比赛中打了,我会为每个玩家创建这个内容。
现在,我想创建一个带有视图的表,列出所有比赛中的球员,以及各种信息,如球员名称/最终位置。我可以通过在视图中添加字段和排序条件来做到这一点。但是我的问题是,下一次我们有一个比赛的时候应该做什么。我只想使用相同的视图设置,但无需克隆以前的视图,只需更改日期过滤条件即可。
所以,我需要用户才能查看比赛页面,然后查看该比赛的结果。然后,如果用户从另一场比赛中去看不同的页面,那么只会显示这些结果。
我希望以干净的方式来做,我不需要克隆视图,只是更改日期。
您可以通过上下文过滤器进行视图来实现此目的。上下文过滤器将处理分类或节点参考,以便您只能使用1个动态视图。但是为了使这项工作有效,您可能希望调整您的内容类型,以便您的视图更容易过滤:
您当前的内容类型全部为参赛者/玩家的信息(比赛日期,玩家名称,最终位置),因此最好将该内容类型命名为Contestant。
然后创建一个新的分类或内容类型:将会处理比赛信息的比赛。保持这些分离是一个更好的方法。
所以我们假设你有一个分类:比赛分类与你所有的比赛设置。然后,您可以将其添加为您的内容类型中的术语参考字段:参赛者。
(添加新的术语参考字段:Tournamentwith widget: select list 。)
创建您的视图:
-
过滤条件 - >内容:Type(= Contestant)
-
页面设置 - >路径:
/ tournaments /%
-
内容相关过滤器 - >内容:有分类术语ID
-
覆盖标题 - >
%1
对于每个分类术语(Tournament),您现在有这个视图有一个页面。所以例如你去 http:// yourdrupal / tournament / 1
,它将只会为你的视图过滤。
我附上一张图片,以便您可以看到我如何配置我的视图
I have a Drupal website where I post tournament results.I have created a content-type where i write the result for 1 person in the tournament. So the fields are like: Date of tournament, player name, final position.If 10 people played in the tournament, I create this content for each player.
Now, I would like to create a table with views, to list all the players in the tournament, and the various info, like player name/final position. I can do that pretty easy by adding the fields and sorting criteria in views. But my problem is, what I should do next time we have a tournament. I would like to just use the same view settings, but without having to clone the previous view, just to change the date filter-criteria.So, I need the user to be able to view tournament page, and then see the results for that specific tournament. Then if the user go to see a different page from another tournament, then only those results will show up.And I wish to do it in a clean way, where I don't have to clone the view and just change date.
You can achieve this by making a view with a contextual filter. The contextual filter will handle a taxonomy or node reference so that you can use only 1 dynamic view. But in order to make this work, you might want to adjust your content type a little so that it's easier for your view to filter them:
Your current content type has all the information of a contestant/player (Date of tournament, player name, final position), so it would be better to name that content type Contestant.Then create a new taxonomy or content type: Tournament which will handle the information of a Tournament. Keeping these separated is a better approach.
So let's say you have a taxonomy: Tournament taxonomy with all your tournaments set up. Then you can add this as a term reference field in your content type: Contestant.(Add a new term reference field: "Tournament" with widget: select list.)
Create your view:
Filter criteria -> Content:Type (=Contestant)
Page settings -> Path:
/tournaments/%
Contextual filter -> Content: Has taxonomy term ID
Override title ->
%1
For each taxonomy term (Tournament) you have this view now has a page. So when for example you go to http://yourdrupal/tournaments/1
it will filter your view only for that tournament.
I attached an image so that you can see how I configurated my view
这篇关于drupal视图动态过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!