Archived topic
Show latest posts on 404 page with php
4 replies · Started by René on February 7, 2023
Hello,
how can I edit the content-404.php to show the most recent posts after the search bar? In the same style as on the archive pages. Is there maybe a shortcode or method i can use?

Hi there,
why not just use a GP Block Element, to create your own 404 template, and then use a GB Query Block or the Core Latest posts block to display the posts ?
Otherwise you will need to create a custom loop in PHP.
Let me know
The file should be easy to pack into the child theme. So I want to solve this with php. Can I create such a custom loop quickly? I tried this: https://davidsutoyo.com/articles/how-to-use-the-wordpress-loop-for-custom-post-types/
I found a good tutorial. I'll look at that first.: https://www.youtube.com/watch?v=rw3jRE8IslM
Glad to hear you found something you can use.
Your alternative would be to look at the themes archive.php and use that as a basis for your child theme 404 template. As that already has a loop for you to work with.