Wie gesagt, das geht mit zwei Schleifen.
Die erste durchläuft einfach die Einträge und zählt einfach die Einträge pro Kategorie und merkt sich die Anzahl in einem Array.
Die zweite Schleife ist im Grunde die normale Ausgabe-Schleife.
1 Schleife:
PHP-Code:
<?php
$fieldName = 'category'; // catalog field name. This is the column name of your select field for the categories
$arrCategories = array(); // stores the categories and its item_count
foreach($this->entries as $entry)
{
$catId = $entry['data'][$fieldName]['raw']; // current category id
if(!array_key_exists($catId,$arrCategories)) // new category
{
$arrCategories[$catId][num_items] = 1;
}
else // increase the items count
{
$arrCategories[$catId][num_items] += 1;
}
}
?>
Die Trennung ist wichtig damit du die Gesamtanzahl ausgeben kannst und nicht pro gefundener Kategorie sich die Zahl in der Ausgabe um 1 erhöht.
Die eigentliche Ausgabe-Schleife erweiterst Du hiermit innerhalb der ersten foreach-Schleife
PHP-Code:
<?php
$catId = $entry['data'][$fieldName]['raw'];
$items = $arrCategories[$catId]['num_items']; // get stored items count
?>
Die Ausgabe einfach per echo darunter z.B.:
HTML-Code:
<div class="items_count"><?php echo $items; ?></div>
----------- hier das komplette catalog_simple template dafür
PHP-Code:
<?php if (count($this->entries)): ?>
<?php
$fieldName = 'category'; // field name for creating collections
$arrCategories = array(); // stores the categories and its item_count
foreach($this->entries as $entry)
{
$catId = $entry['data'][$fieldName]['raw']; // current category id
if(!array_key_exists($catId,$arrCategories)) // new category
{
$arrCategories[$catId][num_items] = 1;
}
else // increase the items count
{
$arrCategories[$catId][num_items] += 1;
}
}
?>
<div class="layout_simple">
<?php foreach ($this->entries as $entry): ?>
<div class="item<?php echo $entry['class'] ? ' '.$entry['class'] : ''; ?>">
<?php
$catId = $entry['data'][$fieldName]['raw'];
$items = $arrCategories[$catId]['num_items'];
?>
<div class="items_count"><?php echo $items; ?></div>
<?php foreach ($entry['data'] as $field=>$data): ?>
<?php if (!in_array($field, array('catalog_name','parentJumpTo'))): ?>
<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; ?>
<?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 Spass beim Ausprobieren,
Gruß Tim
Lesezeichen