Sangfroid 1 сар өмнө
parent
commit
780fdeb73b

+ 8 - 0
assets/styles/app.css

@@ -398,4 +398,12 @@ main h1 a:hover {
     padding: 20px 20px;
    
   }
+
+  .container {
+    flex-wrap: wrap-reverse;
+  }
+
+  .container aside {
+    margin: 20px 0;
+  }
 }

+ 16 - 0
src/Twig/LastArticles.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Twig;
+
+use Twig\Extension\AbstractExtension;
+use Twig\TwigFunction;
+
+class LastArticles extends AbstractExtension
+{
+    public function getFunctions()
+    {
+        return [
+            new TwigFunction('last_articles', [LastRuntimeExtension::class, 'getLastArticles'])
+        ];
+    }
+}

+ 21 - 0
src/Twig/LastRuntimeExtension.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Twig;
+
+use App\Repository\ArticleRepository;
+use Twig\Extension\RuntimeExtensionInterface;
+
+class LastRuntimeExtension implements RuntimeExtensionInterface
+{
+    public function __construct(
+        protected readonly ArticleRepository $articleRepository
+    )
+    {
+        
+    }
+
+    public function getLastArticles(int $limit = 5): array
+    {
+        return $this->articleRepository->findBy(criteria: ['state' => 'published'], orderBy: ['publicationDate' => 'DESC'], limit: $limit);
+    }
+}

+ 8 - 7
templates/_aside.html.twig

@@ -20,17 +20,18 @@
         {% endif %}
     </section>
     
-    {# <!-- Articles Populaires -->
-    <section class="articles-populaires">
-        <h2>Articles Populaires</h2>
+    <!-- Derniers articles -->
+    {% set articles = last_articles() %}
+    <section class="derniers-articles">
+        <h2>Derniers articles</h2>
         <ul>
-        <li><a href="#">Comment démarrer un blog en 2024</a></li>
-        <li><a href="#">Les meilleures astuces SEO</a></li>
-        <li><a href="#">10 plugins indispensables pour WordPress</a></li>
-        <li><a href="#">Comment gagner des abonnés sur les réseaux sociaux</a></li>
+            {% for article in articles %}
+                <li><a href="{{ path('app_view', {'slug': article.slug}) }}">{{ article.title }}</a></li>
+            {% endfor %}
         </ul>
     </section>
     
+    {#
     <!-- Catégories -->
     <section class="categories">
         <h2>Catégories</h2>