Zitat von
Messa
Ist zwar schon ein bisschen her
Aber ich habe gerade etwas ähnliches benötig nur für Jahre.
Falls jemand vor der gleichen Aufgabe steht, hier mein Code.
Damit werden Einträge nach Jahren unterteilt.
news_simple.html5
PHP-Code:
<?php
$year = $this->parseDate("Y", $this->time);
?>
<?php if ($year != $GLOBALS['NEWSYEAR']['YEAR']): ?>
<h2><?php echo $year;?> </h2>
<?php endif; ?>
<div>
<?php echo $this->teaser;?>
</div>
<?php $GLOBALS['NEWSYEAR']['YEAR'] = $year; ?>
Liebe Grüße
Matthias
In Contao 4.13.15 und mit PHP 8.1 wird hierbei im Debug-Modus folgende Fehlermeldung ausgegeben:
PHP-Code:
Warning: Undefined global variable $NEWSYEAR
Um dies zu verhindern habe ich dein Script etwas angepasst:
news_simple.html5
PHP-Code:
<?php $year = \Date::parse("Y", $this->time); ?>
<?php if (isset($GLOBALS['NEWSYEAR']['YEAR'])): ?>
<?php if ($year != $GLOBALS['NEWSYEAR']['YEAR']): ?>
<h2 class="headline"><?= $year ?></h2>
<?php endif; ?>
<?php else: ?>
<h2 class="headline"><?= $year ?></h2>
<?php endif; ?>
<div class="layout_simple arc_<?= $this->archive->id ?> block<?= $this->class ?>">
<a href="<?= $this->link ?>" title="<?= $this->headline ?>">
<?php if ($this->date): ?><time datetime="<?= $this->datetime ?>"><?= \Date::parse("d.m.Y", $this->time) ?></time><?php endif; ?>
<strong><?= $this->headline ?></strong>
</a>
</div>
<?php $GLOBALS['NEWSYEAR']['YEAR'] = $year; ?>
Lesezeichen