From f28561476cca357a97a2a77686df86221fba5985 Mon Sep 17 00:00:00 2001 From: Konstantin Kostov Date: Sun, 10 Nov 2024 15:08:09 +0100 Subject: [PATCH] add recent blog posts --- blog/templates/blog/blog_index_page.html | 85 ++++++++++++------------ home/models.py | 9 +++ home/templates/home/home_page.html | 32 ++++++++- 3 files changed, 82 insertions(+), 44 deletions(-) diff --git a/blog/templates/blog/blog_index_page.html b/blog/templates/blog/blog_index_page.html index fd44827..da226bd 100644 --- a/blog/templates/blog/blog_index_page.html +++ b/blog/templates/blog/blog_index_page.html @@ -15,55 +15,54 @@
{% for post in blogpages %} {% with post=post.specific %} -
-
-

- - - {{ post.title }} - -

-

{{ post.intro }}

-
- {% if post.main_image %} -
- {% with post.main_image as main_image %} - {% if main_image %} - {% image main_image width-1600 class="blog" %}{% endif %} +
+
+

+ + + {{ post.title }} + +

+

{{ post.intro }}

+
+ {% if post.main_image %} +
+ {% with post.main_image as main_image %} + {% if main_image %} + {% image main_image width-1600 class="blog" %}{% endif %} + {% endwith %} +
+
+ {% endif %} +
+
+ +
+ + {% with tags=post.tags.all %} + {% if tags %} +
+

Tags

+
    + {% for tag in tags %} +
  • 🏷️ + {{ tag }} +
  • + {% endfor %} +
+
+ {% endif %} {% endwith %} -
- {% endif %} -
-
- -
- - {% with tags=post.tags.all %} - {% if tags %} -
-

Tags

-
    - {% for tag in tags %} -
  • 🏷️ - {{ tag }} -
  • - {% endfor %} -
-
- {% endif %} - {% endwith %} -
-
{% endwith %} {% endfor %} -
-
+
+ {% endblock %} \ No newline at end of file diff --git a/home/models.py b/home/models.py index 34d4bb1..140aece 100644 --- a/home/models.py +++ b/home/models.py @@ -4,6 +4,8 @@ from wagtail.models import Page from wagtail.fields import RichTextField, StreamField from wagtail.admin.panels import FieldPanel, MultiFieldPanel from wagtailseo.models import SeoMixin, SeoType + +from blog.models import BlogPage from .blocks import HomeContentBlock @@ -57,3 +59,10 @@ class HomePage(SeoMixin, Page): promote_panels = SeoMixin.seo_panels seo_content_type = SeoType.WEBSITE + + def get_context(self, request, *args, **kwargs): + context = super().get_context(request) + # retrieve the last 3 blogposts + recent_blog_items = BlogPage.objects.live().order_by('-first_published_at')[:3] + context['recent_blog_items'] = recent_blog_items + return context \ No newline at end of file diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index a0ff15c..161686a 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -5,7 +5,7 @@ {% block content %}
@@ -45,6 +45,36 @@ +
+

From the blog

+
    + {% for post in recent_blog_items %} + {% with post=post.specific %} +
    +
    +

    + + + {{ post.title }} + +

    +

    {{ post.intro }}

    +
    + {% if post.main_image %} +
    + {% with post.main_image as main_image %} + {% if main_image %} + {% image main_image width-1600 class="blog" %}{% endif %} + {% endwith %} +
    +
    + {% endif %} +
    + {% endwith %} + {% endfor %} +
+
+
{{ page.body }}