How to display the last forum post on the homepage johncms 9.8
7 posts · 71 views
Posts
LatiX
drevils
Redaguoti:
Simba
SuperVaizorius
Redaguoti:
drevils, https://maswap.biz ?))))
Mybe this can help you @drevils
<?php
$db = di(PDO::class);
$req = $db->query("
SELECT
t.id,
t.name,
t.slug,
t.post_count,
t.last_post_author_name,
t.last_post_date,
s.name AS section_name,
s.slug AS section_slug
FROM forum_topic t
LEFT JOIN forum_sections s
ON s.id = t.section_id
ORDER BY t.last_post_date DESC
LIMIT 7
");
?>
<div class="forum-box">
<div class="forum-header">
<h2>💬 Topik Forum Terbaru</h2>
<a href="/forum/">Semua →</a>
</div>
<?php while ($topic = $req->fetch(PDO::FETCH_ASSOC)):
$url = '/forum/' .
$topic['section_slug'] . '/' .
$topic['slug'] . '-' .
$topic['id'] . '/';
?>
<div class="forum-item">
<div class="forum-left">
<a class="forum-title" href="<?= $url ?>">
<?= htmlspecialchars($topic['name']) ?>
</a>
<div class="forum-meta">
<?= htmlspecialchars($topic['section_name']) ?>
·
Oleh <?= htmlspecialchars($topic['last_post_author_name']) ?>
</div>
</div>
<div class="forum-time">
<?= date('d M Y', $topic['last_post_date']) ?>
</div>
</div>
<?php endwhile; ?>
</div>Кадило крутится, лавэха мутится
Here's the code for displaying the last 10 forum topics. For simplicity, you can paste it directly into the template.
If you want to keep the template cleaner, it's better to move the use case call to the controller. However, this code will work as is if you paste it into the template.
<?php
// Get forum topics
$topics = di(\Johncms\Modules\Forum\Application\UseCases\ViewLatestTopicsUseCase::class)->execute();
?>
<?php if (! empty($topics->topics)): ?>
<div class="mb-n3">
<h2 class="h1 fw-bold mt-4 mb-2"><?= d__('system', 'Forum') ?></h2>
<div class="row row-cols-1">
<?php foreach ($topics->topics as $topic): ?>
<div class="col mb-3">
<a class="h6 fw-bold" href="<?= $this->e($topic['url']) ?>"><?= $this->e($topic['name']) ?></a>
<div class="text-muted small pt-1">
<?= $topic['show_last_post_date'] ?>,
<?= $this->e($topic['show_last_author']) ?>
</div>
</div>
<?php endforeach; ?>
</div>
<a href="/forum/" class="btn btn-sm btn-outline-secondary mb-4"><?= d__('system', 'Forum') ?> →</a>
</div>
<?php endif; ?>
Sign in to answer in the topic.
Prisijungti