Advertisement:

Show attachments on custom Index

Aloittaja NIAB, heinäkuu 18, 2013, 08:03:48 IP

« edellinen - seuraava »

NIAB

Hello SMF'ers,

Recently I have tried to get a single attachment from a post to show on my frontpage with either ssi_recentBoardNews, ssi_multiBoardNews, or ssi_recentTopics. Not quite sure how to do it..

Sorry for the lack of example code as I deleted what I had out of the anger of not being able to figure this out.
Have any suggestions?

Oh, I want to be able to place the attachment as uh.. Like and intro image for the news article.

Image on left > News article and desc. on right.
Example


NIAB

Nevermind. Got it with my own little addition to the SSI files. :)

Koodi (SSI Recentattachments Replaced (Partial)) [Valitse]

// We want to show the recent attachments outside of the forum.
function ssi_recentAttachments($num_attachments = 10, $attachment_ext = array(),$topics, $output_method = 'echo')
{
global $smcFunc, $context, $modSettings, $scripturl, $txt, $settings;

// We want to make sure that we only get attachments for boards that we can see *if* any.
$attachments_boards = boardsAllowedTo('view_attachments');

// No boards?  Adios amigo.
if (empty($attachments_boards))
return array();

// Is it an array?
if (!is_array($attachment_ext))
$attachment_ext = array($attachment_ext);

// Lets build the query.
$request = $smcFunc['db_query']('', '
SELECT
att.id_attach, att.id_msg, att.filename, IFNULL(att.size, 0) AS filesize, att.downloads, mem.id_member,
IFNULL(mem.real_name, m.poster_name) AS poster_name, m.id_topic, m.subject, t.id_board, m.poster_time,
att.width, att.height' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : ', IFNULL(thumb.id_attach, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height') . '
FROM {db_prefix}attachments AS att
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = att.id_msg)
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)' . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? '' : '
LEFT JOIN {db_prefix}attachments AS thumb ON (thumb.id_attach = att.id_thumb)') . '
WHERE att.attachment_type = 0' . ($attachments_boards === array(0) ? '' : '
AND m.id_topic IN ({array_int:topics_can_see})') . (!empty($attachment_ext) ? '
AND att.fileext IN ({array_string:attachment_ext})' : '') .
(!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
AND t.approved = {int:is_approved}
AND m.approved = {int:is_approved}
AND att.approved = {int:is_approved}') . '
AND t.id_topic = {int:topic}
ORDER BY att.id_attach DESC
LIMIT {int:num_attachments}',
array(
'boards_can_see' => $attachments_boards,
'attachment_ext' => $attachment_ext,
'num_attachments' => $num_attachments,
        'is_approved' => 1,
        'topic' => $topics,
)
);


Koodi (Custom Index Code (Partial)) [Valitse]

$attachments = ssi_recentAttachments(1, array('jpg', 'png', 'gif', 'bmp'), $news['id'],'array');
foreach ($attachments as $item)
{
      echo '<div style="overflow:hidden;float:left; margin:8px">';
      echo '  <a href="',$news['href'],'">',$item['file']['image']['thumb'],'<br />';

Advertisement: