简体   繁体   中英

How could I get the latest blog posts for Mezzanine page?

I'm new on Mezzanine and I want to display the 8 latest posts on a custom section of the home page.

I already built the QuerySet: BlogPost.objects.filter(publish_date__isnull=False).order_by('-publish_date')[:8]

I've already checked templates/blog/blog_post_list.html but I'm not clear on how can I pass the QuerySet result to the view.

I found an answer Fetch blog entries with bootstrap custom theme and mezzanine . You can use the blog_recent_posts tag from blog_tags. Load the tags at the beginning:

{% load blog_tags %}

And where you want to iterate the recent posts:

<ul>
  {% blog_recent_posts as recent_posts %}
  {% for blog_post in recent_posts %}
    <li>{{ blog_post.title }}</li>
  {% endfor %}
</ul>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM