Last updated October 20, 2006. Created by iandickson on October 20, 2006.
Log in to edit this page.
It is often useful to have pages that build galleries of images on the fly - eg "latest photos from members", where the image is sitting in another node - e.g. "Users Pics".
If you use CCK you can do this.
Advantage - ease of upload of the images (uses image field in CCK instead of having to upload via IMAGE first). Also, if you can code better than me, you can have galleries displayed based on any type of DBd question or taxonomy etc.
This is a cut down version of code at http://drupal.org/node/86104 by hardieas.
<?php
/*
* Grabbed pictures from CCK types and displays as linked picts.
* Is currently LATEST IMAGES, most recent at top, but that is controlled by the MySQL, so alter as you need.
* If your content type is called Users Page 'content_type' is 'content_users_page'
* In this case my field for the picture in the content is called Picture. CCK calls it 'field_picture' - lower case, with underscore.
* Assumes clean urls, if not then change '/node/' to '/?q=node/'
* See also <a href="http://drupal.org/node/86104
" title="http://drupal.org/node/86104
" rel="nofollow">http://drupal.org/node/86104
</a> */
$content_type = 'content_users_page';
$limit = 15;
global $base_url;
$result1 = db_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = '$content_type' AND n.status = 1 ORDER BY n.created DESC LIMIT $limit"));
while ($node = db_fetch_object($result1)) {
$node_loaded = node_load($node->nid);
$output .= '<a href="' . $base_url . '/node/' . $node->nid . '">' ;
$output .= '<img src="' . $base_url . '/' . $node_loaded->field_picture[0][filepath] . '" height="200"></a>';
}
print $output;
?>