SimplePortal

Customization => Custom Coding => Topic started by: Ginarr on August 28, 2009, 10:28:32 PM

Title: Recent Image Attachments Block stretches
Post by: Ginarr on August 28, 2009, 10:28:32 PM
SMF version: 1.1.10
SimplePortal version: 2.2.2
Errors: None.

I'm having an issue with the default "Recent Image Attachments" block. It seems to stretch off to the right side of the page. I have it set to show 12 images, horizontally. However, the effect I was going for was 3 rows, 4 images per row. I'm not sure how to achieve this within SP. How can I keep the default look of the block, and have them in rows that fit to any block size? I have attached an example of what is occurring.

Thanks for any help!
Title: Re: Recent Image Attachments Block stretches
Post by: Ginarr on August 29, 2009, 09:26:59 PM
Any ideas anyone?
Title: Re: Recent Image Attachments Block stretches
Post by: Nathaniel on September 02, 2009, 01:08:38 AM
Moved to the Custom Coding board.

Replace this code:
Code: [Select]
echo '
<table class="sp_auto_align">', $direction ? '
<tr>' : '';

foreach ($items as $item)
{
  echo !$direction ? '
<tr>' : '', '
<td>
<div class="sp_image smalltext">
<a href="', $item['file']['href'], '">', $item['file']['filename'], '</a><br />
', $item['file']['image']['link'], '<br />
', $txt['sp-downloadsCount'], ': ', $item['file']['downloads'], '<br />
', $txt['sp-downloadsPoster'], ': ', $item['member']['link'], '
</div>
</td>', !$direction ? '
</tr>' : '';
}

echo $direction ? '
</tr>' : '', '
</table>';

With this code:
Code: [Select]
echo '
<table class="sp_auto_align">';

$num_per_row = 4;
$i = 1;
foreach ($items as $item)
{
echo (fmod($i, $num_per_row) == 1) ? '
<tr>': '', '
<td>
<div class="sp_image smalltext">
<a href="', $item['file']['href'], '">', $item['file']['filename'], '</a><br />
', $item['file']['image']['link'], '<br />
', $txt['sp-downloadsCount'], ': ', $item['file']['downloads'], '<br />
', $txt['sp-downloadsPoster'], ': ', $item['member']['link'], '
</div>
</td>', (fmod($i, $num_per_row) == ($num_per_row - 1)) ? '
</tr>' : '';
$i++;
}

echo '
</table>';

You can change the number per row, using the variable there.
Title: Re: Recent Image Attachments Block stretches
Post by: Ginarr on September 02, 2009, 08:16:33 PM
Thank you!

I had to tweak the code a bit. It seems the alignment wanted to be centered. So, the 4th image always went down the the second row...

I kept:
Code: [Select]
', $direction ? '
In the code, in-replace of:
Code: [Select]
', (fmod($i, $num_per_row) == ($num_per_row - 1)) ? '
And it does what I want, unless this is the incorrect way? It does work how I imagined though.

This is what I have now:

Code: [Select]
echo '
<table class="sp_auto_align">', $direction ? '
<tr>' : '';
$num_per_row = 4;
$i = 1;
foreach ($items as $item)
{
  echo (fmod($i, $num_per_row) == 1) ? '
<tr>' : '', '
<td>
<div class="sp_image smalltext">
', $item['file']['image']['link'], '<br />
Views: ', $item['file']['downloads'], '<br />
', $txt['sp-downloadsPoster'], ': ', $item['member']['link'], '
</div>
</td>', !$direction ? '
</tr>' : '';
   $i++;
}

echo $direction ? '
</tr>' : '', '
</table>';
SimplePortal 2.3.8 © 2008-2024, SimplePortal