I’m new to both WP and Twig/Timber. I’m working on a website where I need to display a number next to a WP post as such:
- First post
- Second post
- Third post
…And so on
I couldn’t find any information on how to do it. Can I achieve this with Twig/Timber? Also, I don’t know much about it, but if it’s recommended to use ACF for that, I would be open to it.
Thank you
Edit: I would like to display post number(s) both on a page which contains all the blog posts and on each post page.
Edit 2: I’m hoping there is a robust solution which would account for deleted posts
2
Answers
This is something that exists in Twig’s loop variable that should make it super-easy:
https://twig.symfony.com/doc/3.x/tags/for.html#the-loop-variable
You could use a Twig filter to query a custom post number index which is saved in a transient: the order is currently set to the menu order and transient is cached for 1 minute.
Twig
php