Try to learn something about everything, and everything about somethingThomas Huxley “Darwin's bulldog” (1824-1895)

This is an old revision of the document!


Computers

Pureblog

Description

Section One

Addons

archive.php
<?php
declare(strict_types=1);
 
$allPosts = get_all_posts(false);
$postsByYear = [];
 
foreach ($allPosts as $entry) {
    $year = !empty($entry['date']) ? date('Y', strtotime((string) $entry['date'])) : 'Unknown';
    $postsByYear[$year][] = $entry;
}
 
krsort($postsByYear, SORT_NATURAL);
 
$pageTitle = 'Archive';
$metaDescription = 'Browse all published posts by year.';
?>
<?php require PUREBLOG_BASE_PATH . '/includes/header.php'; ?>
<?php render_masthead_layout($config); ?>
<main class=archive>
    <article>
        <h1>Archive</h1>
        <p><?= e((string) count($allPosts)) ?> published posts.</p>
 
        <?php if (!$allPosts): ?>
            <p>No published posts yet.</p>
        <?php else: ?>
            <?php foreach ($postsByYear as $year => $yearPosts): ?>
                <h3><?= e((string) $year) ?> (<?= e((string) count($yearPosts)) ?>)</h3>
                <ul>
                    <?php foreach ($yearPosts as $postItem): ?>
                        <li>
                            <?php if (!empty($postItem['date'])): ?>
                              <!--  <small> -->
                                    <time datetime="<?= e((string) $postItem['date']) ?>">
                                        <?= e(date('D Y-m-d H:i', strtotime((string) $postItem['date']))) ?>
                                    </time>
			   <!--     </small> -->
				&emsp;
                            <?php endif; ?>
                            <a href="/<?= e((string) ($postItem['slug'] ?? '')) ?>">
                                <?= e((string) ($postItem['title'] ?? 'Untitled')) ?>
                            </a>
                        </li>
                    <?php endforeach; ?>
                </ul>
            <?php endforeach; ?>
        <?php endif; ?>
    </article>
</main>
<?php render_footer_layout($config); ?>
</body>
</html>

Further Information

Page created : 02/03/26 08:50 GMT

Page updated : 02/03/26 08:52 GMT


Navigation