Changeset 503776
- Timestamp:
- 02/11/2012 10:24:01 PM (14 years ago)
- Location:
- 404like/trunk
- Files:
-
- 2 edited
-
404Like.php (modified) (9 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
404like/trunk/404Like.php
r317709 r503776 4 4 Plugin URI: http://www.gnetos.de/projekte/404Like 5 5 Description: Es wird keine 404 Fehlermeldung ausgegeben, sondern nach ähnlichen Seiten gesucht und auf eventuelle Treffer weitergeleitet oder eine Liste möglicher Treffer ausgegeben / It is not issued any 404 error message, but looking for similar sites and forwarded to any results or output a list of possible matches 6 Version: 1.0 6 Version: 1.0.2 7 7 Author: Tobias Gafner 8 8 Author URI: http://www.gnetos.de … … 29 29 */ 30 30 function findPostWhereLikeNameTitle($title = "") { 31 $title = strtolower($title); 31 32 $where .= " (post_type = 'post' OR post_type = 'page') AND 32 post_status = 'publish' AND ( post_namelike '%".$title."%' OR post_title like '%".$title."%')";33 post_status = 'publish' AND (LOWER(post_name) like '%".$title."%' OR post_title like '%".$title."%')"; 33 34 return $where; 34 35 } … … 37 38 */ 38 39 function findPostWhereLike($title = "") { 40 $title = strtolower($title); 39 41 $where = " (post_type = 'post' OR post_type = 'page') AND 40 post_status = 'publish' AND ( post_titlelike '%".$title."%')";42 post_status = 'publish' AND (LOWER(post_title) like '%".$title."%')"; 41 43 return $where; 42 44 } … … 53 55 function checkPage() { 54 56 global $wpdb; 57 58 if ( !is_404() ) 59 return; 55 60 56 61 $urltext = $_SERVER['REQUEST_URI']; … … 58 63 $urltext = trim($urltext); 59 64 //Letztes / loeschen 65 //schuetzen 60 66 $urltext = htmlspecialchars($urltext); 61 67 if(strlen($urltext) != 0) { … … 67 73 $searchWord = substr (strrchr ($urltext, "/"), 1); 68 74 //SQL 75 $searchWord = stripslashes($searchWord); 76 $searchWord = str_replace ("'", "", $searchWord); 77 $searchWord = str_replace ('"', "", $searchWord); 78 $searchWord = str_replace (';', "", $searchWord); 69 79 $querystr = "SELECT * FROM $wpdb->posts WHERE ".findPostWhereLike($searchWord); 70 80 $pageposts = $wpdb->get_col($querystr); 71 81 if ($pageposts) { 72 82 ob_start(); 73 if (count($pageposts) == 1) { 83 84 if (count($pageposts) == 1 || ($searchWord == "404Like" || $searchWord == "404like")) { 74 85 foreach ($pageposts as $id) { 75 86 $url = get_permalink($id); … … 77 88 wp_redirect($url,301); 78 89 // Okay, stop. 90 break; 79 91 } 80 92 … … 113 125 if ($pageposts) { 114 126 //Ausgabe 115 echo '<div id="errorresults"><h2 class="twost"> Folgendes Gesucht?</h2><ul>';127 echo '<div id="errorresults"><h2 class="twost">'.__("Folgendes Gesucht").' ?</h2><ul>'; 116 128 foreach ($pageposts as $id) { 117 129 $post_id_7 = get_post($id); … … 126 138 } 127 139 } 140 141 function plugin404Like_filter($redirect, $request) { 142 143 if ( is_404() ) {return false;} 144 return $redirect; 145 } 146 147 add_action( 'template_redirect', 'checkPage' ); 148 add_filter( 'redirect_canonical', 'plugin404Like_filter', 10, 2 ); 128 149 ?> -
404like/trunk/readme.txt
r317709 r503776 4 4 Tags: 404, not found 5 5 Requires at least: 2.7.0 6 Tested up to: 3. 06 Tested up to: 3.3.0 7 7 Stable tag: trunk 8 8 … … 17 17 1. Upload `404Like.php` to the `/wp-content/plugins/` directory 18 18 2. Activate the plugin through the 'Plugins' menu in WordPress 19 3. Place `<?php checkPage(); ? >` in first line of your 404 template page.19 3. Nothing, it works without any other activities - you can test it 20 20 4. Optional add < ? php new404ErrorPage(); ? > to your 404 template page.
Note: See TracChangeset
for help on using the changeset viewer.