Community Documentation

Display list of attachments in teaser view for each node.

Last updated August 26, 2009. Created by derjochenmeyer on January 26, 2008.
Edited by bekasu, ugerhard, Manuel Garcia. Log in to edit this page.

If you put this in your node.tpl.php, it will display a list of attachments in all teasers

 
   <?php if ($page == 0) {      // dont list them in full node view
   
if ($node->links['upload_attachments']['title']){      // anyone know a cleaner way of checking wether there are files uploaded AND listable?

       
print ("<B>".$node->links['upload_attachments']['title'].":</B>");      // Printing how many there are (this is what gets printed out in your "links" <div>)
       
print("<UL>");
        foreach(
$node->files as $file){
            if (
$file->list == 1){        // check wether the files are listable in each case so that we don't print "unlistable" files
               
print ("<LI><A HREF=\"".$file->filepath."\">".$file->description."</A>");    //Printing the description of each file linking to it
               
}
            }
        print (
"</UL>");
    }
   }
  
?>

Comments

Here is a cleaner

Here is a cleaner implementation (Drupal 5+6), that also respects the users permissions to view attachments.

Inspired by and using the same theme functions as the Core Upload module: http://api.drupal.org/api/function/upload_nodeapi/6

  <?php
   
if ($page == 0) {
      if (isset(
$node->files) && user_access('view uploaded files')) {
        if (
count($node->files)) {
          print
theme('upload_attachments', $node->files);
        }
      }
    }
 
?>

----------------------
forward-media.de

Module: Show Uploads in Teasers

This module enables attachments in teasers for Drupal 6. Display can be controlled for each nodetype.

http://drupal.org/project/uploads_in_teasers

----------------------
forward-media.de

Unfortunately, both methods

Unfortunately, both methods don't work with private folder (made with Private upload module).
They both show full path while in private folder Drupal serves only when the path with "system", like .../system/files/folder/file.ext.
Does somebody knows how to help this?

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here