[英]Drupal 8, two contextual filters, how to only use the second one?
I have two taxonomies: "colours" and "shapes". 我有两个分类法:“颜色”和“形状”。 I have a content type called "object" that has a field for "colour", and a field for "shape". 我有一个称为“对象”的内容类型,其中有一个“颜色”字段和一个“形状”字段。
Then I have a simple view that lists content of type "object", and that has two contextual filters: one for "colour", and one for "shape". 然后,我有一个简单的视图,其中列出了“对象”类型的内容,并且具有两个上下文过滤器:一个用于“颜色”,一个用于“形状”。
If I go to /my-view/1, I get a list of all objects that are of colour "blue" (term id 1) 如果我转到/ my-view / 1,则会得到所有颜色为“蓝色”(术语ID为1)的对象的列表。
if I go to /my-view/1/5, I get a list of all the objects that are of colour "blue" and of shape "circle". 如果我转到/ my-view / 1/5,则会得到所有颜色为“蓝色”且形状为“圆形”的对象的列表。
So far so good. 到现在为止还挺好。
What however if I want to list all objects of shape "circle"? 但是,如果我想列出所有形状为“圆形”的对象怎么办? In other words, I only want to specify the second contextual filter. 换句话说,我只想指定第二个上下文过滤器。 Obviously /my-view//5 doesn't work, so how can that be done? 显然/ my-view // 5不起作用,那怎么办呢?
(Note: I'm actually trying to do that programmatically by calling views_get_view_result("objects", "default", 1, 5). In the same way I can call views_get_view_result("objects", "default", 1), but I can't figure out how to call it with only the second contextual filter). (注意:实际上,我实际上是通过调用views_get_view_result(“ objects”,“ default”,1,5)以编程方式做到这一点。我可以通过相同的方式调用views_get_view_result(“ objects”,“ default”,1),但是我不知道如何仅使用第二个上下文过滤器调用它。
(Note2: I'm using Drupal 8, but it's actually the same with Drupal 7) (注2:我使用的是Drupal 8,但实际上与Drupal 7相同)
Never mind, even though I looked for the answer for a couple of days, I found it 5 minutes after posting... 没关系,即使我找了几天的答案,我在发布5分钟后还是找到了答案...
I need to specify an "exception" in the contextual filter - for example "all". 我需要在上下文过滤器中指定一个“例外”,例如“ all”。 Then I can go to /my-view/all/5, or call views_get_view_result("objects", "default", "all", 1) 然后,我可以转到/ my-view / all / 5,或调用views_get_view_result(“ objects”,“ default”,“ all”,1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.