title: How I display wagtail blog post in other pages like homepage
body: <p>Noob here. So as the title I'm trying to display blog around my pages. What I'm trying to achive is:</p>
  <ul>
  <li>homepage who has a list of the latest post.</li>
  <li>Blog index Page.</li>
  <li>Blog category pages.</li>
  <li>a sidebar to use in my other pages.</li>
  </ul>
  <p>So that's has been my step so far:</p>
  <ul>
  <li>set up a wagtail project;</li>
  <li>install wagtail-blog;</li>
  <li>moved blog folder to Lib in my root folder</li>
  <li>set up root, template, and staticfolder.</li>
  </ul>
  <p>As I know by now my blog will show up only in my blog_index_page.html as a http:127.0.0.1/blog/ and blogpost  showing up in 127.0.0.1/blog/blog-post-name. So blog looks like working fine.</p>
  <p>I'm really struggling to unbderstand how to implement the latest post in my homepage; making a category blog page and the sidebar who display latestpost around my site.</p>
  <p>so that's my code:</p>
  <p>blog/models.py</p>
  <pre><code>from django.core.exceptions import ValidationError
  
  from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
  
  from django.conf import settings
  
  from django.contrib.auth import get_user_model
  
  from django.db.models import Count
  
  from django.utils.translation import ugettext_lazy as _
  from django.shortcuts import get_object_or_404
  from django.template.defaultfilters import slugify
  from wagtail.snippets.models import register_snippet
  from taggit.models import Tag
  from wagtail.core.models import Page
  from wagtail.core.fields import RichTextField
  from wagtail.admin.edit_handlers import FieldPanel
  
  from .abstract import (
      BlogCategoryAbstract,
      BlogCategoryBlogPageAbstract,
      BlogIndexPageAbstract,
      BlogPageAbstract,
      BlogPageTagAbstract
  )
  
  
  COMMENTS_APP = getattr(settings, 'COMMENTS_APP', None)
  
  
  class BlogIndexPage(BlogIndexPageAbstract):
      class Meta:
          verbose_name = _('Blog index')
  
      @property
      def blogs(self):
          # Get list of blog pages that are descendants of this page
          blogs = BlogPage.objects.descendant_of(self).live()
          blogs = blogs.order_by(
              '-date'
          ).select_related('owner').prefetch_related(
              'tagged_items__tag',
              'categories',
              'categories__category',
          )
          return blogs
  
      def get_context(self, request, tag=None, category=None, author=None, *args,
                      **kwargs):
          context = super(BlogIndexPage, self).get_context(
              request, *args, **kwargs)
          blogs = self.blogs
  
          if tag is None:
              tag = request.GET.get('tag')
          if tag:
              blogs = blogs.filter(tags__slug=tag)
          if category is None:  # Not coming from category_view in views.py
              if request.GET.get('category'):
                  category = get_object_or_404(
                      BlogCategory, slug=request.GET.get('category'))
          if category:
              if not request.GET.get('category'):
                  category = get_object_or_404(BlogCategory, slug=category)
              blogs = blogs.filter(categories__category__name=category)
          if author:
              if isinstance(author, str) and not author.isdigit():
                  blogs = blogs.filter(author__username=author)
              else:
                  blogs = blogs.filter(author_id=author)
  
          # Pagination
          page = request.GET.get('page')
          page_size = 10
          if hasattr(settings, 'BLOG_PAGINATION_PER_PAGE'):
              page_size = settings.BLOG_PAGINATION_PER_PAGE
  
          paginator = None
          if page_size is not None:
              paginator = Paginator(blogs, page_size)  # Show 10 blogs per page
              try:
                  blogs = paginator.page(page)
              except PageNotAnInteger:
                  blogs = paginator.page(1)
              except EmptyPage:
                  blogs = paginator.page(paginator.num_pages)
  
          context['blogs'] = blogs
          context['category'] = category
          context['tag'] = tag
          context['author'] = author
          context['COMMENTS_APP'] = COMMENTS_APP
          context['paginator'] = paginator
          context = get_blog_context(context)
  
          return context
  
      subpage_types = ['blog.BlogPage']
  
  
  @register_snippet
  class BlogCategory(BlogCategoryAbstract):
      class Meta:
          ordering = ['name']
          verbose_name = _(&quot;Blog Category&quot;)
          verbose_name_plural = _(&quot;Blog Categories&quot;)
  
  
  class BlogCategoryBlogPage(BlogCategoryBlogPageAbstract):
      class Meta:
          pass
  
  
  class BlogPageTag(BlogPageTagAbstract):
      class Meta:
          pass
  
  
  @register_snippet
  class BlogTag(Tag):
      class Meta:
          proxy = True
  
  
  def get_blog_context(context):
      &quot;&quot;&quot; Get context data useful on all blog related pages &quot;&quot;&quot;
      context['authors'] = get_user_model().objects.filter(
          owned_pages__live=True,
          owned_pages__content_type__model='blogpage'
      ).annotate(Count('owned_pages')).order_by('-owned_pages__count')
      context['all_categories'] = BlogCategory.objects.all()
      context['root_categories'] = BlogCategory.objects.filter(
          parent=None,
      ).prefetch_related(
          'children',
      ).annotate(
          blog_count=Count('blogpage'),
      )
      return context
  
  
  class BlogPage(BlogPageAbstract):
      class Meta:
          verbose_name = _('Blog page')
          verbose_name_plural = _('Blog pages')
  
      def get_blog_index(self):
          # Find closest ancestor which is a blog index
          return self.get_ancestors().type(BlogIndexPage).last()
  
      def get_context(self, request, *args, **kwargs):
          context = super().get_context(request, *args, **kwargs)
          context['blogs'] = self.get_blog_index().blogindexpage.blogs
          context = get_blog_context(context)
          context['COMMENTS_APP'] = COMMENTS_APP
          return context
  
      parent_page_types = ['blog.BlogIndexPage']
  '''
  
  
  blog/models.py
  
  from django.db import models
  
  from wagtail.core.models import Page
  from wagtail.core.fields import RichTextField
  from wagtail.admin.edit_handlers import FieldPanel
  
  
  
  
  class HomePage(Page):
      body = RichTextField(blank=True)
  
      content_panels = Page.content_panels + [
          FieldPanel('body', classname=&quot;full&quot;),
      ]
  
  
  def get_context(self, request):
          context = super().get_context(request)
  
          # Add extra variables and return the updated context
          # note: be sure to get the `live` pages so you do not show draft pages
          context['blog_pages'] = BlogPage.objects.child_of(self).live()
          return context
  
  class AboutMe(Page):
      body = RichTextField(blank=True)
  
      template = 'blog/blog_index_page.html'
  
      content_panels = Page.content_panels + [
          FieldPanel('body', classname=&quot;full&quot;),
  
  that's the for loop I'm trying to display the latest post
  
  
               {% block content %}
                &lt;section id=&quot;section-personal-blog&quot; data-bgcolor=&quot;#f5f5f5&quot;&gt;
                  &lt;div class=&quot;container-fluid&quot;&gt;
                      &lt;div class=&quot;row&quot;&gt;
                          &lt;div class=&quot;col-md-6 offset-md-3 text-center&quot;&gt;
                              &lt;h2&gt;Latest Post&lt;/h2&gt;
                              &lt;div class=&quot;small-border&quot;&gt;&lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class=&quot;col-md-12&quot;&gt;
                              &lt;div id=&quot;blog-carousel&quot; class=&quot;owl-carousel owl-theme&quot;&gt;
                                  &lt;div class=&quot;bloglist item&quot;&gt;
                                      &lt;div class=&quot;post-content&quot;&gt;
                                          &lt;div class=&quot;post-image&quot;&gt;
                                              &lt;img src=&quot;{% static 'images/blog-2/pic-blog-1.jpg' %}&quot; alt=&quot;&quot; /&gt;
                                          &lt;/div&gt;
  
                                          &lt;div class=&quot;post-text&quot;&gt;
                                          {% include blog/blog_post.html' with blog=self %}
                                          &lt;/div&gt;
  
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
              &lt;/section&gt;
              {% endblock content %}
  </code></pre>
  <p>Thanks in advice for your time reading this and help me!</p>