I've done a bit of searching. But so far I have not found how to do this.

I have created a new content type using flexinode (for arguments' sake, let's call this content type flexinode-3) that contains nothing more than a title and the by default (with the attachment module) include attachment option.

I would like to list, in a block, a certain number of nodes of this type (which I know how to do). However, I would like the link to go to the first attachment in the node (as opposed to the default node page)?

So this is what I have.

Node title --->(links to)--> Node page

What I would like to have is:

Node Title, attachment size -->(links to) --> Attachment

Hopefully, that makes sense. As usual, any help will be greatly appreciated.

Comments

marcp’s picture

Give this a try in a block (remember to set the input format to PHP code):

$node_type = "page";
$list_no = 3;
$sql = "SELECT nid FROM node WHERE type = '$node_type' ORDER BY changed DESC LIMIT $list_no";
$output = "<ul>";
$result = db_query($sql);
while ($row = db_fetch_object($result)) {
  $node = node_load($row->nid);
  $title = $node->title;
  if ($node->attachments && (count($node->attachments) > 0)) {
    foreach ($node->attachments as $attachment) {
      if (!$attachment['hidden'] && !$attachment['deleted']) {
        $size = format_size($attachment['size']);
        $link = module_invoke('filemanager', 'l', $title . ' - ' . $size, $attachment['fid'], FALSE, array(), TRUE);
        break;
      }
    }
    $output .= "<li>".$link."</li>";
  }
  else {
    $output .= "<li>".l("$node->title", "node/$node->nid")."</li>";
  }
}
$output .= "</ul>";
print $output;

-------
http://www.funnymonkey.com
Tools for Teachers