theme nodes

Node Attachments: Display and Theme File Size

This script will allow you to display the file size of attached files uploaded to a node. It will determine and display the appropriate size of the file in bytes, kilobytes, and megabytes.

<?php
$item
= $node->filesize[0]; // change this to the correct field name
if($item['filesize'] < 1024) {
   print (
$item['filesize']);
   print (
" bytes");
}
elseif (
$item['filesize'] < 1048576) {
  
$filesize = $item['filesize'];
  
$filesize = $filesize / 1024;
  
$filesize = round($filesize, 2);
   print (
$filesize);
   print (
" kB");
}
else {
  
$filesize = $item['filesize'];
  
$filesize = $filesize / 1048576;
  
$filesize = round($filesize, 2);
   print (
$filesize);
   print (
" MB");
}
?>

Tested in Drupal 5 with the Contemplate module. Originally from http://drupal.org/node/254020#comment-915919

Drupal 5 & Drupal 6 Tip

There is a dedicated function for similar results at least in Drupal 5 and 6:

<?php
 
print format_size($file->filesize);
?>

ARCHIVE: Node layout and display snippets

Last modified: October 28, 2009 - 00:56

This section outlines and provides snippets for customizing node layouts and node display

(If you want to customize the layout of your FULL page, see the full page layouts and sections collection of snippets).

Scroll down for some example snippets, that you can copy-and-paste and use in your custom node.tpl.php or node-type.tpl.php layout files.

For more information about node template files, refer to the PHPTemplate documentation.

Node.tpl.php

Last modified: October 16, 2009 - 08:47

This template controls the display of a node, and a node summary. It can only affect the output of the $content variable.

Available variables

$content
Node content, teaser if it is a summary.
$date
Formatted creation date.
$directory
The directory the theme is located in, e.g. themes/garland or themes/garland/minelli.
$id
The sequential ID of the node being displayed in a list.
$is_front
True if the front page is currently being displayed.
$links
Node links.
$main (4.6)
True if the node is appearing in a context, like the front page, where only the teaser should be shown. No longer used in 4.7 and later.
$name
Formatted name of author.
$node (object)
The node object. To view all of the properties of a current $node object, put the following line of code in your node.tpl.php: <pre><?php print_r($node); ?></pre>
$node_url
Link to node.
$page
True if the node is being displayed by itself as a page.
$picture
HTML for user picture, if enabled.
$sticky
True if the node is sticky.
$submitted
Syndicate content
 
 

Drupal is a registered trademark of Dries Buytaert.