我怎样才能得出这个观点?
列表 -> l_user
我有一个List
节点,其中有一个用户引用字段 (l_user
)。故事 -> s-user
然后我有Story
节点,它也有一个用户引用字段 (s_user
)。List
和Story
之间没有直接联系。
我想向 List
添加一个视图,其中列出引用 list
引用的同一用户的所有故事。基本上类似于 SELECT Stories WHEREstory.s_user = this list.l_user
和 l_user
是此视图所在列表中引用的用户。
到目前为止,视图正在通过 node:type Story
进行过滤,但我不确定使用什么(参数/过滤器等)将 story s_user
链接到 <代码>列出l_user。
这对于视图可行吗?
List -> l_user
I have aList
node that has a user-reference field (l_user
).Story -> s-user
I then haveStory
nodes that also have a user-reference field (s_user
).- There is no direct connection between
List
andStory
.
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.
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
.
Is this doable with Views?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Views 参数来做到这一点。您想要做的是按用户过滤该列表,然后让用户从您当前所在的节点(或更具体地说,节点的用户引用字段)进行过滤。因此,您需要做的是为视图提供一个等于节点的用户引用字段的参数。
为此,请正常设置视图,就像显示每个用户的节点一样。因此,您可能会看到如下视图:
其中用户是用户每个页面上的参考字段称为“故事用户参考”。
现在,在参数下添加内容:故事用户引用的参数。现在,视图将仅显示参数中指定的用户发布的节点。问题是,在一个块中,没有可以指定的参数:您需要提供一个默认参数。
仍在内容:故事用户参考的参数配置窗格中,选择参数不存在时采取的操作下的提供默认参数。您将获得多种选项,但它们都不是您正在寻找的:当前节点的用户参考字段。
因此,您需要使用 PHP 代码 操作并使用以下代码:
这将根据从当前页面路径检索到的节点 ID 加载节点,并返回该节点的用户引用字段(更改
field_list_user
为列表节点上用户引用字段的名称)。因此,如果我在节点 17 上,其用户引用字段状态为用户 4,则将传递给视图的参数为 4。然后,视图将仅显示视图中用户引用也为 4 的节点。
保存您的查看、创建块显示并将其放置在您想要的任何位置。当您访问带有用户引用字段的节点页面时,该块将填充引用的用户的节点。
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:
Where the user is a user reference field on each page called Story user reference.
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.
So you'll need to use the PHP code action and use the following code:
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).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.
我建议从列表节点获取所有用户引用并将它们传递到视图参数中。因此,您的代码看起来像这样(未经测试):
假设您有一个名为“list_view”的视图,其显示名为“block_1”(当您将鼠标悬停在显示上时可以看到计算机名称)。该显示需要是一个节点视图,具有节点类型“story”的过滤器和设置为采用多个值的内容 user_l 参数。几乎可以肯定该代码中存在错误,但我知道一般概念是有效的,因为我之前已经做过几次了。
I'd suggest getting all of the user references from the list node and passing those into a views argument. So your code would look something like this (untested):
That assumes you have a view named 'list_view' with a display named 'block_1' (you can see the machine name when you hover over the display). That display needs to be a node view with a filter of node type 'story' and an argument of content user_l set to take multiple values. There's almost certainly a bug in that code, but I know the general concept works, as I've done it several times before.
要解决这个问题,您需要下载 NodeReferrer。 http://drupal.org/project/nodereferrer
它提供了 CCK 节点参考字段的对应部分。
然后您可以在视图中调用该字段“Node Referrer”。
To solve this you need to download NodeReferrer. http://drupal.org/project/nodereferrer
It provides a counter part to CCK's node reference field.
Then you can call the field "Node referrer" in your View.