, Display Random Posts on 404 Page
, Display Random Posts on 404 Page

Display Random Posts on 404 Page

This same query can be modified to show the most popular posts, most commented posts among others.

If you want to display a random list of posts in WordPress, then you can simply add this code to your 404 template where you want to display a random list of posts from your site.

<?php 
$posts = get_posts('orderby=rand&numberposts=5'); 
   foreach($posts as $post) { ?>
        <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
        </li>
   <?php } ?>
</ul>

This same query can be modified to show the most popular posts, most commented posts among others. This article describes the process of improving the 404-page on your WordPress website to make it more useful in general.

Add comment

Do you have a
WordPress problem?

Select what best describes your goals:

Cart

HOLD ON!

Do you have a
WordPress problem?

Become a WordPress Pro
with our easy to follow guides .

Hire an Expert to quickly solve
any WordPress related task.

We use cookies to provide an awesome experience on our website. By continuing to use this site, you agree to our tasty cookies.
🍪 Accept Cookies
Privacy Policy