How can I work out this view?

前端 未结 3 584
终归单人心
终归单人心 2021-01-22 11:26
  • List -> l_user I have a List node that has a user-reference field (l_user).
  • Story -> s-user I then have
相关标签:
3条回答
  • 2021-01-22 12:09

    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.

    0 讨论(0)
  • 2021-01-22 12:12

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

    $user_ids = array();
    foreach ($list_node->l_user as $user_reference) {
      $user_ids[] = $user_reference['uid'];
    }
    $view = views_get_view('list_view');
    return $view->preview('block_1', array(implode(',', $user_ids));
    

    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.

    0 讨论(0)
  • 2021-01-22 12:14

    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.

    0 讨论(0)
提交回复
热议问题