deadjournal/views/post/list.php

86 lines
2.7 KiB
PHP
Raw Normal View History

2025-01-08 22:46:44 +05:00
<?php if (isset($archiveLabel)): ?>
<h2>Month: <?= e($archiveLabel) ?></h2>
<?php else: ?>
<h2>All posts</h2>
<?php endif; ?>
<?php if (!empty($posts)): ?>
<?php foreach ($posts as $post): ?>
<div class="post">
<p class="post_info"><small><?= e($post['created_at']) ?></small></p>
<h3>
<a href="<?= HOME_DIRECTORY ?>index.php?url=post/view/<?= e($post['id']) ?>">
<?= e($post['title']) ?>
</a>
</h3>
<?php if (isAdmin()): ?>
<p>
<a href="<?= HOME_DIRECTORY ?>index.php?url=admin/edit/<?= e($post['id']) ?>">
Edit
</a>
</p>
<?php endif; ?>
<?php
$result = getExcerptWithMore($post['content']);
?>
<div>
<?= nl2br($result['excerpt']) ?>
</div>
<?php if (!empty($post['tags'])): ?>
<p class="tags">
Tags:
<?php
$separator = '';
foreach ($post['tags'] as $tag) {
// Print the separator (which is empty for the first tag, then becomes ", ")
echo $separator;
$url = HOME_DIRECTORY . 'index.php?url=post/tag/' . e($tag['name']);
$name = e($tag['name']);
// Output the link for this tag
echo '<a href="' . $url . '">' . $name . '</a>';
// Now that we've printed one tag, change separator to ", "
$separator = ', ';
}
?>
</p>
<?php endif; ?>
<?php if ($result['hasMore']): ?>
<!-- If there's more, show a "Read more" link -->
<p>
<a href="<?= HOME_DIRECTORY ?>index.php?url=post/view/<?= e($post['id']) ?>">
Read more...
</a>
</p>
<?php endif; ?>
</div>
<?php endforeach; ?>
<!-- Pagination block -->
<?php if (!empty($totalPages) && $totalPages > 1): ?>
<p>
<?php for ($i = 1; $i <= $totalPages; $i++): ?>
<?php if ($i == $currentPage): ?>
<strong><?= $i ?></strong>
<?php else: ?>
<a href="<?= HOME_DIRECTORY ?>index.php?url=post/index&page=<?= $i ?>"><?= $i ?></a>
<?php endif; ?>
&nbsp;
<?php endfor; ?>
</p>
<?php endif; ?>
<?php else: ?>
<p>No posts</p>
<?php endif; ?>