ElkArte Community

Project Support => General ElkArte discussions => Topic started by: badmonkey on December 04, 2015, 10:08:13 am

Title: SSI recent attachments
Post by: badmonkey on December 04, 2015, 10:08:13 am
Hi ladies and gents!  I would like to display recent attachments on a home page.  Rather than download links, I would like to display the images themselves, perhaps even linking to the original containing post.  I know enough php to be dangerous.   :D   What would I need to do to make this happen?  Thanks!
Title: Re: SSI recent attachments
Post by: emanuele on December 04, 2015, 12:36:08 pm
Code: [Select]
<?php
require_once('SSI.php');

$attaches = ssi_recentAttachments(10, array(), 'return');

foreach ($attaches as $attach)
{
    echo 'something';
}

The something is stuff you can pick from $attach that is an array containing three indexes: member, file, topic. Each of these contains a bunch of info about the attachment, you can use print_r or var_dump to see the content. ;D
Title: Re: SSI recent attachments
Post by: badmonkey on December 04, 2015, 05:26:08 pm
I'm doing something very wrong.  All I get is the same output as calling ssi_recentAttachments().  Trying to debug, it appears it isn't entering the loop, unless that's wrong too.  lol

Code: [Select]
<?php  
require("SSI.php");

$attaches = ssi_recentAttachments(10, array(), 'return');
$i = 1;
foreach ($attaches as $attach)
{
$i++;
}
echo $i;
?>


This yields the table and 1.  Let's sit back and laugh at my dumb noob mistake.   :D
Title: Re: SSI recent attachments
Post by: emanuele on December 05, 2015, 02:21:45 am
Darn, it's array....
Code: [Select]
$attaches = ssi_recentAttachments(10, array(), 'array');
Title: Re: SSI recent attachments
Post by: badmonkey on December 05, 2015, 01:50:45 pm
Now why didn't I see that?  It's working perfectly now.  Thanks emanuele! 
Title: Re: SSI recent attachments
Post by: emanuele on December 05, 2015, 02:47:04 pm
Probably for the same reason I didn't see it. xD
You are welcome. ;D