Create a snippet for displaying a card style "post".

This commit is contained in:
2026-04-20 09:17:00 +10:00
parent 1a5fe54439
commit 269d314758
2 changed files with 35 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ Kirby::plugin(
],
"snippets" => [
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
"collection/post" => __DIR__ . "/snippets/collection/post.php",
],
"hooks" => [
/**

View File

@@ -0,0 +1,34 @@
<div class="card mb-3<?= r($post->pinned()->isTrue(), " border-light") ?><?= r($post->isDraft(), " text-secondary") ?>">
<div class="card-body py-1">
<h3 class="card-title mb-0">
<a href="<?= $post->url() ?>" class="text-reset text-decoration-none"><?= $post->title() ?></a>
<?php if ($post->pinned()->isTrue() || $post->isDraft()) : ?>
<div class="float-end">
<?= r($post->pinned()->isTrue(), kirbytag("fa", "thumbtack", ["class" => "fa-xs"])) ?>
<?= r($post->isDraft(), kirbytag("fa", "pencil-ruler", ["class" => "fa-xs"])) ?>
</div>
<?php endif ?>
</h3>
<small class="d-inline-block text-body-secondary pb-2">
<?= kirbytag("fa", "calendar-days") ?>
<?php if (date_diff(date_create($post->created()->toDate("Y-m-d")), date_create($post->updated()->toDate("Y-m-d")))->format("%a") > 0) : ?>
Updated on <span title="Originally posted on <?= $post->created()->toDate('l \t\h\e\ jS \of F Y') ?>"><?= $post->updated()->toDate('l \t\h\e jS \of F Y') ?></span>
<?php else : ?>
Posted on <?= $post->created()->toDate('l \t\h\e jS \of F Y') ?>
<?php endif ?>
</small>
<hr class="mt-0">
<?= $post->text()->textExcerpt(600, false) ?>
</div>
<div class="card-footer">
<small>
<div class="float-end">
<a href="<?= $post->url() ?>"><?= kirbytag("fa", "angle-double-right") ?> Read The Rest</a>
</div>
<?php if (($user = kirby()->user()) and $user->role()->isAdmin()) : ?>
<a href="<?= $post->panel()->url() ?>" target="_blank"><?= kirbytag("fa", "edit") ?></a>
<?php endif ?>
</small>
</div>
</div>