Connor Wilson
  • Home
  • About
  • Archives
  • Contact

Musings on design, sports and life.

connorwilson: Just started using Facebook a week ago. Already starting drama, lmao.

Follow me »

Quicksilver Style Livesearch with WordPress

Posted on September 1st in General — 109 Comments so far. Got something to say?

Over at OrderedList, John Nunemaker wrote a guide on using jQuery (or Prototype, whichever works for you) to implement a Quicksilver Type Livesearch. QuickSilver is an awesome Mac app that lets you search through your apps, files, etc… By typing fragments of a string. From there you can launch apps, open files, and tons of other options.

I just type 'F' an it presents Firefox.

I just type 'F' an it presents Firefox.

Get Your Files Setup

There’s a few Javascript files you’ll need to setup before we can start editing our WordPress theme. Here are the files you’ll need to save and upload to your theme’s folder:

  • Quicksilver.js — This processes the input and gives back a value based on matches with the search area (our posts).
  • Livesearch jQuery Plugin by John. This is what makes everything work together, with the live input and the search area.
  • And of course, you’ll need to go get jQuery.

Now set those files up in header.php like this:

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/jquery.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/quicksilver.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/scripts/jquery.livesearch.js"></script>

Once that’s setup, it’s time to get going on the real stuff.

Archive.php vs. Archives.php

Before we continue, I’m just going to clear something up. There are always these two files in your theme’s directory, but what’s the difference? Basically, one is a page template and the other is the display for the archived posts, like dated archives and the like.

  • Archive.php is the archive that shows posts based on date, author, category, etc… This is the file we will be editing!
  • Archives.php is the page template, which in the end just links off to pages that use the former page to display.

If you go to the archives link at the top of this page in my navigation, it will take you to my Archives.php page. If you click a link on that page, it will take you to my QS Livesearch enabled Archive.php.

Modifying the Loop

What we’re going to do is basically put all the posts we have in a list so the JS we downloaded can do it’s magic. Find the loop in your archive.php file and we’re going to change it to the code below. I’ll explain it after.

<?php if (have_posts()) : ?>
<div class="post">
<form method="get">
<div class="livesearch">
<input type="text" value="" name="q" id="q" />
		</div>
</form>
<ul id="posts">
	<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
 
	<?php endwhile; ?>
	</ul>
</div>
 
<?php else : ?>
 
Oops, no posts!
 
<?php endif; ?>

This is going to display the form and text input that users can use to refine the posts on the page. It’s also going to take all the posts and put each one in an LI. The reason we only display the title is because the script searches through all the text in each LI. Besides that, it’s nothing fancy. Get the posts, display the posts to work with the JavaScript.

Potential Problems

The first thing I ran into with this was that if you have a low number of posts per page, you won’t get many items to search through. You can try writing different queries for each option, but in the end, there is a plugin that can fix this. It’s called Different Posts per Page.

A word of warning — you will need to sign up for their stupid newsletter to activate their plugin. It’s worth the trouble, though. Just block the letter if you don’t want it, because this is the easiest solution to the problem.

Next, it’s always possible that you might have uploaded your JS files into a different directory than the /scripts/ that I provided in the code. Make sure the files are included properly before asking any questions, because this is the number problem that users have when doing something involving JavaScript.

If you have any questions that don’t fall into those two common errors, then feel free to leave a comment and I’ll help you out. You can see the example as I mentioned above, right here an my site. For instance, go check out my Design category page.

Posted in General with 109 Comments.

A Resurgence of Tutorial Sites

Posted on August 30th in General — 60 Comments so far. Got something to say?

Posted in General with 60 Comments.

How to Create a WordPress Login Form Overlay

Posted on August 25th in General — 34 Comments so far. Got something to say?

Posted in General with 34 Comments.

Jays vs. Red Sox

Posted on August 23rd in Sports — 18 Comments so far. Got something to say?

Posted in Sports with 18 Comments.

New Design and Overall Changes

Posted on August 21st in Design — 70 Comments so far. Got something to say?

Posted in Design with 70 Comments.

« Older Entries
Blog Categories
  • Apple (12)
  • Blogging (44)
  • Design (32)
  • Free Resources (4)
  • Freelance (4)
  • Friday Roundup (4)
  • General (45)
  • Ideas (16)
  • Improve Your Blog (7)
  • Learning Ruby (4)
  • My Sites (16)
  • Personal (27)
  • Quick (9)
  • Ramblings (30)
  • SEO (15)
  • Site Development (31)
  • Sports (1)
  • WordPress (22)
Subscribe

Get updates to the RSS reader of your choice by subscribing.

    Subscribe to RSS

  • Subscribe in a Reader
  • Subscribe by email
Search

You can search all posts on the site, or visit the full archives to look around some more.

Top Commenters
  • Virtual Family (3)
  • Water Treatment (3)
  • Beauty Salon (3)
  • Leicestershire Web Design (3)
  • Loan Relief (2)
  • used tires (1)
  • Miadeo (1)
  • Seo (1)
  • sinema (1)
  • my blog (1)
Recent Posts

All content is copyright © Connor Wilson 2006-2008. If you want to use something just ask. Powered by WordPress.