Um das ganze komplett zu machen:
Hier das ganze mit Sortierung nach der Kategorie-Spalte in der tl_taxonomy Tabelle.
Ganz oben in der Variablen $fieldName den Namen des Kategorie-Feldes eintragen.
Der Rest sollte von selbst passieren.
PHP-Code:
<?php if (count($this->entries)): ?>
<?php
$fieldName = 'category'; // field name for creating collections
$emptyCategoryName = 'Ohne Kategorie'; // create a seperate category for all items that are not selected in category
$arrCategories = array(); // collects all catalog entries
$arrSorted = array(); // collects all sorted catalog entries
$index = 0;
foreach($this->entries as $entry)
{
$act = $entry['data'][$fieldName]['value'];
// check if category already exists / or not
if( array_key_exists($act, array_flip($arrCategories) ) )
{
$arrSorted[$act][] = $entry; // fill existing category node
$index++;
}
else
{
if( !strlen($act) ) // Incase entry has no categorie selected, build free category
{
$act = $emptyCategoryName;
}
$arrSorted[$act][0] = $entry; // create new category node
}
$arrCategories[] = $entry['data'][$fieldName]['value'];
}
/**
* Get category sorting from tl_taxonomy
*/
$catalog = $this->entries[0]['tablename'];
$arrCategorySorted = array();
foreach($this->entries as $entry)
{
$this->import('Database');
$objField = $this->Database ->prepare("SELECT $fieldName FROM $catalog WHERE id=?")
->limit(1)
->execute($entry['id']);
if(!$objField->numRows) continue;
$taxId = $objField->$fieldName;
$objField = $this->Database ->prepare("SELECT sorting, name FROM tl_taxonomy WHERE id=?")
->limit(1)
->execute($taxId);
if(!$objField->numRows) continue;
$sorting = $objField->sorting;
$category = $objField->name;
if( array_key_exists($category, $arrSorted ) )
{
// Remember sorting number in first element of each category
$arrSorted[$category][0]['data'][$fieldName]['sorting'] = $sorting;
$arrCategorySorted[$sorting] = $arrSorted[$category];
}
}
// Sort
ksort($arrCategorySorted);
?>
<?php foreach($arrCategorySorted as $key => $entries): ?>
<div class="layout_simple block ce_accordion">
<div class="toggler <?php echo str_replace(' ', '', $key); ?>"><h3><?php echo $entries[0]['data'][$fieldName]['value']; ?></h3></div>
<div class="accordion <?php echo str_replace(' ', '', $key); ?>">
<?php foreach($entries as $entry): ?>
<div class="item<?php echo $entry['class'] ? ' '.$entry['class'] : ''; ?>">
<?php foreach($entry['data'] as $field => $data): ?>
<?php if (!in_array($field, array('catalog_name','parentJumpTo'))): ?>
<?php if($field == $fieldName) continue; ?>
<div class="field <?php echo $field; ?>">
<div class="label"><?php echo $data['label']; ?></div>
<div class="value"><?php echo $data['value']; ?></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<?php if ($entry['showLink'] && $entry['link']): ?>
<div class="link"><?php echo $entry['link']; ?></div>
<?php endif; ?>
<?php if ($entry['linkEdit']): ?>
<div class="linkEdit"><?php echo $entry['linkEdit']; ?></div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<?php if ($this->condition): ?>
<div class="condition"><?php echo $this->condition; ?></div>
<?php else: ?>
<p class="info">There are no entries matching your search.</p>
<?php endif; ?>
<?php endif; ?>
Viel Spaß damit,
Der Tim