Permalink
Browse files

initial commit to git repo

  • Loading branch information...
0 parents commit ccd791bccd39edd787ac705dbf2f8305f8c3f6bb @jnunemaker committed Dec 15, 2008
@@ -0,0 +1 @@
+.DS_Store
@@ -0,0 +1,28 @@
+var AddictedToLiveSearch = {
+ url:'',
+
+ init:function() {
+ AddictedToLiveSearch.s = $('s');
+ if (AddictedToLiveSearch.s) {
+ AddictedToLiveSearch.s.autocomplete = 'off';
+ var form = AddictedToLiveSearch.s.up('form');
+ form.insert(new Element('div', {'id':'addicted_results'}));
+ new Form.Element.Observer(AddictedToLiveSearch.s, 0.8, AddictedToLiveSearch.showResults);
+ AddictedToLiveSearch.box = $('addicted_results');
+ }
+ },
+
+ showResults:function(element, value) {
+ AddictedToLiveSearch.showPage(value, 1);
+ },
+
+ showPage:function(s, page) {
+ AddictedToLiveSearch.box.show();
+ new Ajax.Updater( 'addicted_results', AddictedToLiveSearch.url, {
+ method:'get',
+ parameters:'s=' + s
+ });
+ }
+}
+
+$(document).observe('dom:loaded', function() { AddictedToLiveSearch.init(); });
@@ -0,0 +1,28 @@
+<?php
+/*
+Plugin Name: Addicted To Live Search
+Plugin URI: http://addictedtonew.com/archives/145/wordpress-live-search-plugin/
+Description: Adds live search with ajax to the default search box
+Author: John Nunemaker
+Version: 1.1
+Author URI: http://addictedtonew.com/
+*/
+
+function addicted_add() {
+ echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/prototype/1.6/prototype.js"></script>' . "\n";
+ echo '<script type="text/javascript" src="' . get_bloginfo('siteurl') . '/wp-content/plugins/addicted_live_search/live_search.js"></script>' . "\n";
+ echo '
+ <script type="text/javascript">
+ AddictedToLiveSearch.url = "' . get_bloginfo('siteurl') . '/wp-content/plugins/addicted_live_search/search_results.php";
+ </script>';
+}
+
+add_action('wp_footer', 'addicted_add');
+
+function addicted_search_rewrite($wp_rewrite) {
+ $rules = array('wp-content/plugins/addicted_live_search/search_results.php' => '/');
+ $wp_rewrite->rules = $rules + $wp_rewrite->rules;
+}
+
+add_filter('generate_rewrite_rules', 'addicted_search_rewrite');
+?>
@@ -0,0 +1,4 @@
+1. Upload the entire folder named addicted_live_search to your wp-contents/plugins folder.
+ Path must be wp-contents/plugins/addicted_live_search/ or it won't work.
+2. Login to your wordpress administration area and activate the plugin.
+3. Make sure you have wp_footer() in footer.php of your current theme and that your search field has an id of 's', which is the default.
@@ -0,0 +1,32 @@
+<?php
+require('../../../wp-blog-header.php');
+
+if (isset($_GET['s']) && trim($_GET['s']) != '') {
+
+ $term = mysql_real_escape_string(trim($_GET['s']));
+ $sql = "SELECT
+ *
+ FROM
+ wp_posts wp
+ WHERE
+ wp.post_type = 'post' AND
+ wp.post_status = 'publish' AND
+ wp.post_date <= '" . date('Y-m-d H:i:s', time()) . "' AND
+ ((wp.post_title LIKE '%${term}%') OR (wp.post_content LIKE '%${term}%'))
+ ORDER BY
+ wp.post_date DESC
+ LIMIT 10";
+ $posts = $wpdb->get_results($sql);
+
+ if (count($posts) > 0) {
+ echo '<ul>';
+ foreach($posts as $post) {
+ echo '<li><a href="' . get_permalink($post->ID) . '">' . the_title('', '', false) . '</a></li>';
+ }
+ echo '</ul>';
+ } else {
+ echo '<p>No results found.</p>';
+ }
+
+}
+?>

0 comments on commit ccd791b

Please sign in to comment.