DEV Community

Cover image for Setting up a 'Recent Posts' section using Twig
Gabe
Gabe

Posted on

1 1

Setting up a 'Recent Posts' section using Twig

I'm embarrassed to admit that when I initially setup my Grav blog, I did so without much forethought. My entire home page was coded directly into the WYSIWYG. It was pretty simple so I got away with it for a bit.

It wasn't until I went to update my "Recent Essays" section today that I realized how poorly I had setup my homepage. So I spun up my local environment and got to work on a quick fix.

Auto pull the five most recent posts

Using this post I found in the Grav documentation, I was able to take the first example and tailor it to my needs with ease. I came up with the following:

And with that, I no longer have to worry about manually updating my homepage every time I write a new blog post. I simply write, publish, and call it a day.

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay