# List Recent Posts URL: /bengal/docs/build-sites/customize/recipes/list-recent-posts/ Section: recipes Tags: cookbook, filters, where, sort -------------------------------------------------------------------------------- List Recent Posts Display the most recent posts from a section using Bengal's query filters. The Pattern {% let posts = site.pages |> where('section', 'blog') |> where('draft', false) |> sort_by('date', reverse=true) |> limit(5) %} <ul class="recent-posts"> {% for post in posts %} <li> <a href="{{ post.href }}">{{ post.title }}</a> <time>{{ post.date | date('%B %d, %Y') }}</time> </li> {% end %} </ul> What's Happening Filter Purpose where('section', 'blog') Only pages in the blog/ directory where('draft', false) Exclude drafts sort_by('date', reverse=true) Newest first limit(5) Take only 5 date('%B %d, %Y') Format date (alias for dateformat) Variations Any Section With Featured Exclude Current {# All non-draft pages, any section #} {% let recent = site.pages |> where('draft', false) |> sort_by('date', reverse=true) |> limit(10) %} {% let posts = site.pages |> where('section', 'blog') |> sort_by('date', reverse=true) %} {% let featured = posts |> first %} {% let rest = posts |> offset(1) |> limit(4) %} <div class="featured"> <h2>{{ featured.title }}</h2> <p>{{ featured.description }}</p> </div> <ul class="more-posts"> {% for post in rest %} <li><a href="{{ post.href }}">{{ post.title }}</a></li> {% end %} </ul> {# In a sidebar, show recent posts excluding the current one #} {% let others = site.pages |> where('section', 'blog') |> sort_by('date', reverse=true) |> limit(6) %} {% for post in others if post._path != page._path %} <a href="{{ post.href }}">{{ post.title }}</a> {% end %} Info Seealso Template Functions — All filter options Group by Category — Organize posts by category -------------------------------------------------------------------------------- Metadata: - Author: lbliii - Word Count: 239 - Reading Time: 1 minutes