Hi,
I'm building a site (Drupal5.1) that contains a CCK content type for articles. The article type has a nodereference field attached so that authors can generate a list of related articles ("If you like this article you might also like..." functionality.).
I've been able to build a custom function that displays a list of the related nodes at the end of the article by doing:
# template.php function display_related_articles($node) { if ($node->field_related_articles['0']['view'] != '') { return _phptemplate_callback('box_related_articles', array ('node' => $node)); } }
# box_related_articles.tpl.php <ul> <?php foreach ($node->field_related_articles as $related) { ?> <li><?php print $related['view']; ?></li> <?php } ?> </ul>
I'd now like to replicate this same functionality into a sidebar block, but I'm hitting a brick wall somewhere. Using the views module I've generated a custom block using the "Arguments" system to do the following:
# Argument Type Node Reference: Related Articles - Display All Values
# Argument Code if ($type == 'block' && arg(0) == 'node' && is_numeric(arg(1))) { $currentnode = arg(1); $query = db_query("SELECT field_related_articles_nid FROM content_field_related_articles WHERE nid = %d ORDER BY field_related_articles_nid ASC", $currentnode); $args = array(); while ($result = db_fetch_object($query)) { $args[] = $result->field_related_articles_nid; } } return $args;
This works to a certain degree, but it's showing some odd quirks. The test node I'm using references 6 other articles, but the block is displaying 7 entries: 5 of the referenced articles, 1 seemingly random article, and a link back to the article currently being displayed.
I have a feeling I'm being dense and missing something supremely simple here, but I can't for the life of me work out what it is. I've poured over the docs on drupal.org and although I've found lots of explanations on how to display reverse references ("List all the nodes that reference this one") I can't seem to find a solution for this, what I originally thought was simple, use case.
This site is currently under development so I can't point you towards a URL, but if anyone wants to see an export of the view then I could stick it up on pastebin.
Thanks in advance.
G.
-- ------------------------------------------------------------------------ Blog: http://polytechnic.co.uk Photos: http://flickr.com/photos/garrettc Music: http://last.fm/user/garrettc1