I needed to apply the concepts outlined at http://drupal.org/node/101748 to create a listing of node teasers that contained thumbnail images. That article was written for 4.7 and was useful, but not completely helpful for Drupal 5.1 which I am running. Here's a way to create a teaser list with thumbnails ... keep in mind I am also not a Drupal expert, but a Drupal learner. This is just what worked for me.
Install the Modules
You will need to install and enable the following modules:
Configure Imagecache
The imagecache settings are at http://www.example.com/admin/settings/imagecache (replace example.com with your domain). We are going to define a generic thumbnail namespace that can be reused for different purposes. This namespace will exist to scale the uploaded images to a size of 100x100 pixels for display in the listings.
Modify the Node Type with CCK
This example is modifying the Blog node so navigate to http://example.com/admin/content/types/blog. We will be adding an image field to the existing node type.
Create Content and Upload an Image
Now create a new instance of the modified node.
Create a Module
I use a custom module for each site that I do that contains functions specific to that site I would like to keep removed from the templates. Not sure if it is the correct Drupal way of doing things, but it works for me. This is a simple module with 2 files, example.info and example.module The module itself will contain a simple function that can be called from any template to generate a teaser list of that node type complete with images.Create the following two files and upload them to an example folder in your modules directory. Don't forget to activate the module before proceeding.
Create example.info
name = "Teaser List"
description = "Example Teaser listing of a node complte with thumbnail images."
version = "1.0"
Create example.module
function example_getBlogTeasers() {This is not ideal code ... but it is functional code. There are many ways to tweak the output of this listing. In a production environment you may want to enclose the content in divs or as a list that can be styled and displayed to your liking. You may need to alter the query to select your specific node type. For the purpose of this tutorial we will keep it simple and move on.
$results = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'blog');
$output = '';
while ( $data = db_fetch_object($results) ) {
$node = node_load($data->nid);
$output .= l($node->title, 'node/'.$node->nid);
$output .= theme('imagecache', 'thumbnail', $node->field_thumbnail[0]['filepath']);
$output .= $node->teaser;
$output .= '';
}
return $output;
}
Modify Your Theme
THis is the easy part. Simply add the following code to a template page you would like to display your teaser list on:<?php echo example_getBlogTeasers(); ?>
Conclusion
It took me a while to figure this out so I do hope it helps someone. This is the first content I've contributed to Drupal, so by all means let me know if there is an easier or more correct way to accomplish any of the above.Here's a list of articles that I used to figure this out:
Comments
wwwouldn't it be a lot
wwwouldn't it be a lot easier to just use Views?
Is this the method you're
Is this the method you're using to display your own photo gallery? Thanks for the writeup ...
This is a method I've used
This is a method I've used in the past for clients. The photo gallery on the site is being displayed with the Picasa module. I started loosing all of my sites available disc space to images so decided to offload them to a free service.
What can God never see?
Hi!
Without taking into account the issue of establishing a stone by God, which he won't be able to pick up, how do you think, may be something in this world, what can God never see?
Post new comment