Просмотр поста #562073: How to display the last forum post on the homepage johncms 9.8

.
drevils

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>