dongluobei9359 2010-08-13 05:21
浏览 9
已采纳

我该如何解决这个问题?

  • 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.

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?

  • 写回答

3条回答 默认 最新

  • donglin1192 2010-08-14 19:47
    关注

    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:

    • 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)

    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:

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

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了