Skip to content

Instantly share code, notes, and snippets.

@sillybean sillybean/404.php
Created May 18, 2012

Embed
What would you like to do?
Better 404 Error Page
<?php get_header(); ?>
<div id="content" class="section">
<h2>I'm sorry. I couldn't find the page you requested.</h2>
<p>You can try searching for it or looking for it in the <a href="/sitemap">site map</a>.</p>
<?php get_template_part( 'searchform' ); ?>
<?php
global $wp_query;
$wp_query->query_vars['is_search'] = true;
$s = str_replace("-"," ",$wp_query->query_vars['name']);
$loop = new WP_Query('post_type=any&s='.$s);
?>
<?php if ($loop->have_posts()) : ?>
<p>I'm searching for the name of the page you tried to visit... was it one of these?</p>
<ol>
<?php while ($loop->have_posts()) : $loop->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
</ol>
<?php endif; ?>
</div> <!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.