Created
March 7, 2019 13:24
-
-
Save WordPress-Handbuch/d0736c5ff257f8b45cecb1d2653744a5 to your computer and use it in GitHub Desktop.
404 handler for WordPress search showing posts alternatives related to the page not found, and a search form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $wp; | |
$urlquery = $wp->request; | |
$urlquery = preg_replace("/(\.*)(html|htm|php)$/","",$urlquery); | |
$parts = explode('/', $urlquery); | |
$keyword = end($parts); | |
echo 'Mal sehen, ob es zum Thema "' . $keyword . '" Blogbeiträge gibt...'; | |
$query = new WP_Query( array( 's' => $keyword ) ); | |
// Fuer das Such-Plugin Relevanssi die Kommentarzeichen der folgenden zwei Zeilen entfernen: | |
//$query->parse_query( $args ); | |
//relevanssi_do_query( $query ); | |
if(!empty($query->posts)): | |
?> | |
<h4>Ist bei diesen Blogbeiträgen etwas Interessantes dabei?</h4> | |
<ul class="posts-list"> | |
<?php | |
foreach($query->posts as $single_post) { | |
$title = apply_filters('the_title', $single_post->post_title); | |
$url = get_permalink($single_post); | |
echo '<li><a href="' . $url . '">' . $title .'</a></li>'; | |
} | |
?> | |
</ul> | |
<?php endif;?> | |
<h4>Falls nicht, dann geben Sie gerne ein anderes Stichwort ein:</h4> | |
<?php get_search_form(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment