Skip to content
Advertisement

How do I display 3 recent posts in footer with Timber?

So, I am beating my head over this for 2 days now. How do I display 3 recent posts in footer using Timber and Twig? I am using a starter theme from Timber. What I did inside my footer.php file:

JavaScript

And inside my footer.twig I tried displaying them:

JavaScript

Now the problem is it displays nothing. If I replace featured with posts in footer.twig, it displays whatever posts are on the current page. It seems to me that Timber doesn’t process my post query and I don’t know why is that. I was looking for an answer but didn’t find one. Also, this is my first post here, so I am sorry in advance if it is confusing.

Advertisement

Answer

So, I just found the answer to my own question 🙂 In case someone has a similar problem, I resolved it by adding the variable to the context inside functions.php:

JavaScript

Then inside my footer.twig I use it like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement