If you've been going in order, the "Downloads" node is up and essentially working. It just doesn't look like you might expect it to just yet. This next section will delve into how to theme the downloads, allowing you to essentially duplicate the DOCman appearance.
Since we want the download nodes to have their own styling, we will need to make some changes to the template files to allow specific templates for a view.
By default, any styling we try to perform on the download nodes will affect all other nodes as well. This probably isn't what we had in mind, so let's correct that.
Note: In this tutorial, I am using the standard Garland theme, but the process should be the same for others.
First we need tell the template engine to look for the right file when it is rendering the nodes. Inside of your template directory, open the "template.php" file. Look for the phptemplate_preprocess_page function (around line 55) and change the entire function body from
function phptemplate_preprocess_page(&$vars) {
$vars['tabs2'] = menu_secondary_local_tasks();
// Hook into color.module
if (module_exists('color')) {
_color_page_alter($vars);
}
}
to
function phptemplate_preprocess_page(&$variables) {
if ($node = menu_get_object()) {
$variables['node'] = $node;
$suggestions = array();
$template_filename = 'page';
$template_filename = $template_filename . '-' . $variables['node']->type;
$suggestions[] = $template_filename;
$variables['template_files'] = $suggestions;
}
}
(actually, I just comment out the old function. You know, in case something goes wrong.)
Save and close "template.php."
I'm not actually sure this is necessary. If the attached file is not displaying in the node, add the following code to the end of node.tpl.php (just before the last </div> tag.)
<?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>");
}
}
?>
We need to specify a custom template for download pages. Make a copy of the template file "page.tpl.php" and rename it to "page-<node_type>.tpl.php," where <node-type> is the name we gave to the node type when we created the content type. In our case, we would name the file page-download.tpl.php.
Open the new file in a text editor. Around line 69 (just after the mission) add a new line and add
<div id="downloads-page">
I close the div after the rss icon is displayed (but you might want to enclose more/less within the div) by adding
</div>
around line 80. This will let us theme the entire page that the node appears in, from buttons that appear at the top of the page when a download node is displayed to the footer.
Just as we copied page.tpl.php to page-downloads.tpl.php, we need to do the same for the node.tpl.php file. Actually, the modification is very minor and easy to miss. In the first div, change the name of the class from "node" to "downloads-node". In other words, change the line from
<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
to
<div id="node-<?php print $node->nid; ?>" class="downloads-node downloads-node-<?php print $zebra; ?><?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?>">
This will let us theme the body of the node. Note the
downloads-node-<?php print $zebra; ?>
in the modified line. This will allow you to alternate the background colors of even/odd nodes if you'd like.
We are coming along. So far, we can theme the download nodes as we like, but the layout isn't quite how I'd want it. We need to create a new template file named views-view-fields--<view_tag_name>.tpl.php, or views-view-fields--downloads.tpl.php. Note that I changed the name for the view tag to "downloads" as opposed to the singular "download" that we used for the node type. This isn't necessary, and you may keep them consistent. This file is actually a copy of views-view-fields.tpl.php, which is located in the modules/views/theme directory, but I have completely changed the structure. You may modify it to suit your needs/wants/desires.
Inside of the views-view-fields--downloads.tpl.php file, paste the following:
<?php
// $Id: views-view-fields.tpl.php,v 1.6 2008/09/24 22:48:21 merlinofchaos Exp $
/**
* @file views-view-fields.tpl.php
* Default simple view template to all the fields as a row.
*
* - $view: The view in use.
* - $fields: an array of $field objects. Each one contains:
* - $field->content: The output of the field.
* - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
* - $field->class: The safe class id to use.
* - $field->handler: The Views field handler object controlling this field. Do not use
* var_export to dump this object, as it can't handle the recursion.
* - $field->inline: Whether or not the field should be inline.
* - $field->inline_html: either div or span based on the above flag.
* - $field->separator: an optional separator that may appear before a field.
* - $row: The raw result object from the query, with all data it fetched.
*
* @ingroup views_templates
*/
?>
<div id="download-view">
<div id="download-titlebar">
<span class="download-date">
<?php print $fields['changed']->content; ?>
</span>
<div class="download-title">
<?php print $fields['title']->content; ?>
</div>
</div>
<div id="download-body">
Originally posted on <?php print $fields['created']->content; ?>
<div class="download-description">
<?php print $fields['body']->content; ?>
</div>
<div class="download-filename">
<?php print $fields['field_filename_fid']->content; ?>
</div>
<div class="download-comments">
Comment count: <?php print $fields['comment_count']->content; ?>
</div>
<div class="download-tags">
Tags: <?php print $fields['tid']->content; ?>
</div>
</div>
</div>
We can now apply css styling to control the layout of the fields in the node, but first we have one more file to modify.
Create another file named views-view-unformatted--downloads.tpl.php, or better yet, copy modules/views/theme/views-view-unformatted.tpl.php and rename it. All we need to do is add the line
<?php print $classes['changed']; ?>
after the comment header, but before any actual code.
All that's left to do now is to create CSS styles to control to look of the download nodes. This is where a browser add-on, such as "Web Developer" for Firefox comes in quite handy.