Success! Thank you Calguy - I now have it sorting by Category (either alphabetically or by the order they were entered into the system). For those just tuning in, here's what I did:
Call the module on your page - {cms_module module='Uploads' category='all'}
Create a UDT (called 'sort'):
Code: Select all
if (!function_exists('do_sort')) {
function do_sort($a, $b) {
return $a->upload_category_id > $b->upload_category_id;
}}
$data = $params['data'];
usort($data, 'do_sort');
$smarty->assign('sorted', $data);
If you'd like to sort your categories alphabetically, simply change 'upload_category_id' to 'category' in the UDT above.
In the Uploads module, change the following in your Summary Template:
from
{foreach from=$items item='entry' name='uploads'}
to
{sort data=$items}<!--calls the newly created UDT-->
{foreach from=$sorted item='entry' name='uploads'}<!--swaps $items to $sorted-->
I haven't tested Calguy's accordion template, but here's a simple one that will group items under their category heading, and should be a good launching point for your own:
Code: Select all
<div id="categories">
{assign var='current_category' value=''}
{sort data=$items}
{foreach from=$sorted item='entry' name='uploads'}
{if isset($entry->download_url)}
<!-- check for new Category start -->
{if $current_category != $entry->category}
<h3>{$entry->category}</h3>
<!-- assign this items category to current -->
{assign var='current_category' value=$entry->category}
{/if}
<!-- item -->
<!-- generate a file download link, size and any additional fields -->
<p><strong><a class="downloadurl" href="{$entry->download_url}" title="{$entry->upload_name}" target="_blank">{$entry->upload_name}</a></strong> <span class="size">({$entry->size} kb)</span></p>
{if isset($entry->fields)}
{foreach name=fields from=$entry->fields key='fldname' item='field'}
{$field.name}: {$field.value}<br/>
{/foreach}
{/if}
<!-- item -->
{/if}
{/foreach}
</div>
And in case you haven't been paying attention (or read as many posts on the topic as I have!), to further protect any files in your chosen directory, make sure to drop a .htaccess file into the directory containing your files that contains:
Code: Select all
<limit GET POST HEAD DELETE>
order deny,allow
deny from all
allow from 127.0.0.1
</limit>
NOTE: this method only seems to work with modules that use a script to access the files (such as Uploads or Download Manager). If the module produces a direct path to the file that matches it's actual location, this .htaccess file will block ALL access, so don't use it!
Once again, thanks to Calguy, and of course uniqu3 (Goran) for his solution (which can be read at
http://www.i-do-this.com/blog/69/Sortin ... in-foreach).