简体   繁体   English

限制 drupal 视图仅显示用户创建的节点

[英]limit drupal view to show only nodes created by user

I'm using drupal 7. I created a view for displaying nodes of a specific content type (eg products).我正在使用 drupal 7。我创建了一个视图来显示特定内容类型的节点(例如产品)。 When viewing the page, I want only those products displayed which were created by the user (currently shows all products).查看页面时,我只想显示用户创建的那些产品(当前显示所有产品)。

I would like to do it without using a url filter so the url would be simply:我想在不使用 url 过滤器的情况下做到这一点,因此 url 将很简单:

/myproducts /我的产品

Use the filter "User: Current".使用过滤器“用户:当前”。 If that doesn't work, try with a relationship如果这不起作用,请尝试建立关系

With the Advanced Help module you can see "Example to filter content by the current logged-in user" : http:// yoursite /help/views/example-filter-by-current-user使用高级帮助模块,您可以看到“当前登录用户过滤内容的示例” :http:// yoursite /help/views/example-filter-by-current-user

And there said:那里说:

Creating the relationship创建关系

In order to have access to the author of the content, it is important to create a relationship between the current content type, and users.为了访问内容的作者,重要的是在当前内容类型和用户之间建立关系。

Under Advanced in the right column, select add next to Relationships.在右栏中的高级下,select 添加到关系旁边。

Select Content: Author and click on Add and configure relationships. Select 内容:作者并单击添加和配置关系。 Leave the settings as they are and click on Apply (all displays).保持设置不变,然后单击应用(所有显示)。

You now have access to the user data related to the content you are viewing.您现在可以访问与您正在查看的内容相关的用户数据。

Filtering the view过滤视图

Now you need to filter the view to display only content authored by the current user.现在您需要过滤视图以仅显示当前用户创作的内容。 This >data is now available for the content because you have created the relationship in the step >above.该 >data 现在可用于内容,因为您已在上面的步骤 > 中创建了关系。

Next to Filter criteria click on add to add a new filter to your view.在过滤条件旁边单击添加以将新过滤器添加到您的视图中。

Filter the list of fields by selecting User next to Filter at the top.通过选择顶部过滤器旁边的用户来过滤字段列表。 You now have more >fields than before due to the relationship you created.由于您创建的关系,您现在拥有比以前更多的 > 字段。

Select User: Current from the list and click on Add and configure filter criteria. Select 用户:列表中的当前并单击添加并配置过滤条件。

Since this field is only visible due to the relationship you created, author will already be selected under Relationship.由于此字段仅因您创建的关系而可见,因此已在关系下选择了作者。 This shows that the relationship you created is being used for the filter field.这表明您创建的关系正在用于过滤器字段。

Select Yes under Is the logged in user, and click on Apply (all displays). Select 是在是登录用户下,然后单击应用(所有显示)。

If you have authored content of the type Blog Post, you should now see a list of those posts under the preview section at the bottom.如果您创作了博客帖子类型的内容,您现在应该在底部的预览部分下看到这些帖子的列表。

Saving & testing the view保存和测试视图

Here's what I used to make it work.这是我用来让它工作的。

  1. Under relationships, add content:author在关系下,添加内容:作者
  2. Under contextual relationship, add user: authentication name and relationship: author (or whatever you called your relationship).在上下文关系下,添加用户:身份验证名称和关系:作者(或任何您称之为关系的名称)。

And if you want to be even more sure, add to filter: user current and add relationship.如果您想更加确定,请添加到过滤器:当前用户并添加关系。

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

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