[support] CCK/nodereference/Views - Block of referenced nodes?

Garrett Coakley garrett at polytechnic.co.uk
Mon Mar 26 16:30:42 UTC 2007


On 26 Mar 2007, at 15:53, Larry Garfield wrote:

[ack! sent this from the wrong account so I suspect the original got  
held by the list software, apologies list admins]


Thanks for wading in here Larry,

> It looks like in your argument code you're trying to pass in an  
> argument for each related nid.  That's wrong. :-)

Heh, that figures. *:)


> Instead, just pass the current nid (which you are getting  
> correctly) as the argument, and then use that single argument to  
> filter the nodereference field.  You don't need any SQL for it;  
> Views will do the "WHERE field_related=$nid" part itself.

Okay, that makes more sense, but I think I'm getting confused with  
the views.module terminology and where exactly I'm supposed to be  
filtering the nodereference field. This is what I have now (with some  
inline comments as to my understanding):

# Block
Provides Block
View Type: List View
Nodes per Block: 10 (usually there are only 3-5 referenced nodes, but  
I want to have some headroom for expansion)

# Fields
Node: Title, as link (this is what I want the block to display right?)

# Arguments
Node Reference: Related Articles, Display All Values (take the  
argument from the handling code and apply it to these values)

# Argument Handling Code
if ($type == 'block' && arg(0) == 'node' && is_numeric(arg(1))) {
   $currentnode = arg(1);
}
return $currentnode;

# Filters
Node: Distinct is distinct (in case there are less than 10 entries I  
only want one of each)
Node: Type Is One Of 'Article' (not entirely sure I need this as  
shouldn't the argument handling code only return articles anyway?)


This view now returns 10 articles, but only 2 of them are actually  
referenced by the current article, which seems to be happening  
through luck rather than any determination on my part *:).

G.

--
------------------------------------------------------------------------
   Blog: http://polytechnic.co.uk
Photos: http://flickr.com/photos/garrettc
  Music: http://last.fm/user/garrettc1





More information about the support mailing list