简体   繁体   English

Drupal视图-根据URL过滤内容

[英]Drupal views- filter content based on URL

I have a view which shows particular content type(advertisement). 我有一个显示特定内容类型(广告)的视图。 My content type has a field "show only on page" which is a text type. 我的内容类型有一个字段“仅显示在页面上”,这是一种文本类型。 Here I will give the page where that particular content should be shown. 在这里,我将给出显示该特定内容的页面。

I have created a block which is shown on /blog which is showing all content of advertisement. 我创建了一个显示在/ blog上的块,该块显示了广告的所有内容。 But I want the ads to show only in the block if the url matches. 但我希望广告仅在网址匹配的情况下才显示在该区块中。

For eg. 例如。 If an adv is added say "abc" with "show only on page" as "/blog/europe/*" then in the block "abc" should be shown only when person visits a url say /blog/europe/france etc. 如果添加了广告,则将“仅在页面上显示”的“ abc”说成“ / blog / europe / *”,那么只有当用户访问网址时,在“ abc”框中才显示“ / blog / europe / france等”。

Now I have created a view but I don't know how to pass the "show only on page" field as an argument in the view. 现在,我已经创建了一个视图,但是我不知道如何在视图中传递“仅在页面上显示”字段作为参数。

Basically I would like something like below to happen: 基本上,我希望发生以下情况:

if "page url" contains "show only on field" then select the content
else don't select.

Is this type of filter possible in drupal views? 在drupal视图中可以使用这种类型的过滤器吗? I am hoping views argument may save my day. 我希望观点争论可以挽救我的生活。

There are different ways of passing arguments to a view, depending on how you are displaying the view. 将参数传递给视图的方式有多种,具体取决于您如何显示视图。 I hope i understand your question correctly. 希望我能正确理解您的问题。 Sounds like you are wanting to filter the contents of your view by the value of "show only on page" field. 听起来好像您希望通过“仅在页面上显示”字段的值来过滤视图的内容。 The actual value of "show only on page" to filter by is passed via the URL. 通过URL传递要过滤的“仅在页面上显示”的实际值。

To do this you must add a contextual filter to your view. 为此,您必须在视图中添加上下文过滤器。 Then you would add the value of "show only on page" as a parameter in the URL to that view. 然后,您可以将“仅在页面上显示”的值作为参数添加到该视图的URL中。 In this case, when you load the view it will only display those nodes in which "show only on page" field is equal to the value you passed in the URL. 在这种情况下,加载视图时,它将仅显示“仅在页面上显示”字段等于您在URL中传递的值的那些节点。

For example the path to you page view might be "path/to/view". 例如,您的页面浏览路径可能是“路径/至/视图”。 You would then add the "show only on page" argument to this url (eg "path/to/view/value_of_show_only_on_page"). 然后,您可以在该网址中添加“仅在页面上显示”参数(例如,“ path / to / view / value_of_show_only_on_page”)。 When you use this URL your view will be filtered so only content where the value of "show only on page" is equal to "value_of_show_only_on_page" is displayed. 使用此URL时,将过滤视图,因此仅显示“仅在页面上显示”值等于“ value_of_show_only_on_page”的内容。

Note in Drupal 6 "contextual filters" are referred to as "arguments" in the Views UI. 请注意,在Drupal 6中,“上下文过滤器”在视图UI中称为“参数”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM