Sure
I use the following code:
PHP Code:
// Thumbnails
if($foruminfo['forumid'] == 22 AND $getpostid = $DB_site->query_first("
SELECT postid FROM " . TABLE_PREFIX . "post WHERE threadid = $thread[threadid] LIMIT 1"))
{
$attachment = $DB_site->query_first("
SELECT filename, attachmentid, IF(thumbnail_filesize > 0, 1, 0) AS hasthumbnail
FROM " . TABLE_PREFIX . "attachment
WHERE postid = $getpostid[postid]
ORDER BY rand() LIMIT 1
");
$attachmentid = $attachment['attachmentid'];
$hasthumbnail = $attachment['hasthumbnail'];
}
// Thumbnails
which reads out the attachmentids only from the images which have thumbnails. This excludes all txt or pdf or other files which are not images.
ORDER BY rand() LIMIT 1 tells him to output a randomly chosen attachment.
Together with the following conditional in the
threadbit -Template it generates this beautiful gallery
HTML Code:
<if condition="$show['threadicons']">
<td class="alt2">
<if condition="$foruminfo[forumid] == 22 AND $hasthumbnail">
<img src="attachment.php?attachmentid=$attachmentid&stc=1&thumb=1" /> <else />
<if condition="$show['threadicon']"><img src="$thread[threadiconpath]" alt="$thread[threadicontitle]" border="0" /><else /> </if>
</if>
</if>
For some reasons this query doesn't work for any image and I couldn't find out why. But as most of the images work I don't care that much about it. Feel free to take my code and modify it