我该如何解决这个问题? [英] How can I work out this view?

查看:102
本文介绍了我该如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 列表 - > l_user 我有一个具有用户参考字段( l_user )的列表节点。

  • 故事 - > s-user 然后我有 Story 节点也有用户引用字段( s_user )。

  • 列表故事之间没有直接的连接。 >
  • List -> l_user I have a List node that has a user-reference field (l_user).
  • Story -> s-user I then have Story nodes that also have a user-reference field (s_user).
  • There is no direct connection between List and Story.

我想添加一个视图到列表,其中列出了引用相同的所有故事用户列表引用。基本上就像 SELECT stories WHERE story.s_user = this list.l_user l_user 是列表中引用的用户视图已开启。

I want to add a view to List that lists all the stories that reference the same user that list references. Basically something like SELECT stories WHERE story.s_user = this list.l_user and l_user is the user referenced in the list this view is on.

到目前为止,该视图正在被节点过滤:类型故事但我不确定使用什么(参数/过滤器等)将 story s_user 链接到列表l_user

So far the view is being filtered by node:type story but I'm not sure what to use (arguments/filter, etc) to link the story s_user to the list l_user.

这是否适用于Views?

Is this doable with Views?

推荐答案

您可以使用Views参数。您尝试做的是过滤该用户列表,并让用户从当前使用的节点(或更具体地说,节点的用户参考字段)过滤。那么你需要做的就是提供一个等于该节点的用户参考字段的参数的视图。

You can do this with a Views argument. What you're trying to do is filter that list by user, and you get the user to filter by from the node you're currently on (or more specifically, the node's user reference field). So what you'll need to do is supply Views with an argument that is equal to the node's user reference field.

为此,将视图设置为正常,好像您正在显示每个用户的节点。所以你可能会有一个看法:

To do that, set up your view as normal and as if you were showing every user's node. So you might have a view that's like:


  • 第1页(按用户1)

  • 2(由用户1)

  • 第3页(由用户2)

  • 第4页(按用户2)

  • 第5页(按用户1)

  • Page 1 (by User 1)
  • Page 2 (by User 1)
  • Page 3 (by User 2)
  • Page 4 (by User 2)
  • Page 5 (by User 1)

用户是每个名为故事用户的用户参考字段参考

现在,在参数下,为 Content:Story用户参考添加参数。现在,该视图将仅显示由参数中指定的用户发布的节点。问题是,在一个块中,没有参数指定:您需要提供一个默认参数。

Now, under Arguments add an argument for Content: Story user reference. Now, the view will only show nodes that are posted by the user specified in the argument. The problem is, in a block, there is no argument to specify: you need to provide a default argument.

仍然在参数配置窗格中的内容:故事用户参考,选择下提供默认参数 。你会得到各种各样的选择,但是没有一个是你正在寻找的:当前节点的用户参考字段。

Still on the argument configuration pane for Content: Story user reference, select Provide default argument under Action to take if argument is not present. You'll get a variety of options, but none of them are what you're looking for: the current node's user reference field.

所以你需要使用

$node = node_load(arg(1));
return $node->field_list_user[0]['uid'];

根据从当前页面的路径检索到的节点ID加载节点,并返回节点的用户引用字段(将 field_list_user 更改为列表节点上的用户引用字段的名称)。

This loads a node based on the node ID retrieved from the current page's path and returns the node's user reference field (change field_list_user to the name of the user reference field on the list nodes).

所以如果我在用户引用字段指定用户4的节点17上,那么传递给视图的参数就是4。视图中具有用户引用的节点也是4。

So if I'm on node 17 whose user reference field states user 4, the argument that'll be passed to the view is 4. The view will then only show nodes in the view who have user references that are also 4.

保存视图,创建块显示,并将其放在任何位置。当您访问带有用户参考字段的节点页面时,该块将使用引用的用户节点填充。

Save your view, create a block display, and place it wherever you want. When you visit a node page with a user reference field, the block will populate with the referenced user's nodes.

这篇关于我该如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆