WordPress Search Function Notes

by Jeff Starr on Wednesday, July 26, 2006

Code to call an external WordPress search form:

<?php include (TEMPLATEPATH . "/searchform.php"); ?>

Code for a standard, inline WordPress search form:

<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><input name="s" type="text" id="s" size="33" maxlength="99" />
<input type="submit" class="submit" value="Search &raquo;" /></p>
</form>

Code to search through multiple categories when using customized, individual category pages:

<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><input name="s" type="text" id="s" size="33" maxlength="99" />
<input type="hidden" name="cat" value="1,2,3,4,5,6" />
<input type="submit" class="submit" value="Search &raquo;" /></p>
</form>

Code to try if the search function fails and your blog is located in a directory other than root:

<form method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">

or:

<form method="get" id="searchform" action="http://yourblog.com/blog/index.php">

This particular search function uses the site URL (note the trailing slash) as the form action, and employs a .gif image as the input type:

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<div><input type="text" value="Search" name="s" id="s" />
<input type="image" src="<?php bloginfo('stylesheet_directory'); ?>/images/search.gif" id="searchsubmit" value="Search" />
</div></form>

Just for fun, here is bit of php that should (have not checked it yet) output a value indicating the total number of search results:

<?php
$search_count = 0;

$search = new WP_Query("s=$s & showposts=-1");
if($search->have_posts()) : while($search->have_posts()) : $search->the_post();
$search_count++;
endwhile; endif;

echo $search_count;
?>

Another neat trick is to include a default message if some condition is met. For example, here we are telling WordPress to display the text string, "Search Perishable Press", unless someone is actually searching for something:

<?php if (!is_search()) { 
$search_text = "Search Perishable Press"; 
} else { 
$search_text = "$s"; 
} ?>
<form method="get" id="searchform" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" id="s" name="s" value="<?php echo wp_specialchars($search_text, 1); ?>" />
<input type="submit" id="searchsubmit" value="Search!" />
</form>

Here is a core hack to get WordPress to search pages in addition to posts for older (1.5) versions of WordPress (I think newer versions do this automatically). Open the file wp-includes/classes.php and look around line #493 for the following code:

if ($this->is_page) {
     $where .= ' AND (post_status = "static")';
} else {
     $where .= ' AND (post_status = "publish")';
}

Replace (comment out) that entire chunk of code and replace it with this:

if ($this->is_page) {
     $where .= ' AND (post_status = "static")';
} elseif ($this->is_search) {
     $where .= ' AND (post_status = "publish" OR post_status = "static")';
} else {
     $where .= ' AND (post_status = "publish")';
}

Happy searching! :)

Read more

Backup that Database with phpMyAdmin

by Jeff Starr on Wednesday, July 26, 2006

Optimal Database Export Options
DB Export Settings
Backing up your database as often as possible is essential. For WordPress, as well as for other applications, plugins and other scripts that help automate the task are easily obtainable. However, for several reasons, it is a good idea to understand the process of manually creating a backup copy of your database. This brief tutorial1 should help cement the process into a solid reference. We are assuming that you have an SQL database and have access via phpMyAdmin.

Before reading through the gory details written below, check out the screenshot to the left (click on the image). That picture is literally worth a thousand characters. Another way to avoid the forthcoming verbose explanation is to skip the next paragraph to the neatly summarized list.

First, open phpMyAdmin and select from the dropdown menu the database you wish to backup. If there is only one database available, select it by clicking on its name. Now, along the upper-right row of tabs, click on the "export" tab. From that screen, under the subcategory "Export", click on "select all" and make sure that the "SQL" option is selected. Then, under the SQL Options/Structure category, make sure "Structure", "Add DROP TABLE", "Add AUTO_INCREMENT value", and "Enclose table and field names with backquotes" are checked. Finally, under the "SQL Options/Data" category, make sure "Data", "Complete inserts", and "Use hexadecimal for binary fields" are checked. The "Export type" should be set to "INSERT". Finally, check "Save as file" and do not change the "File name template". It is advisable to save both a compressed copy and a zipped copy. Click "Save" and you are done.

  1. Open phpMyAdmin, select database, click on "Export"
  2. Within the "Export" screen, click on "Select All" and select "SQL"
  3. Then check "Structure", "Add DROP TABLE", "Add AUTO_INCREMENT..", and "Enclose table.."
  4. Also check "Data", "Complete inserts", and "Use hexadecimal.."
  5. Check "Save as file", select a compression format, and "Go"!

Footnotes

Read more

New Online Vector Drawing Tool

by Jeff Starr on Tuesday, July 25, 2006

LiTha-Paint.com
LiTha-Paint
Quality web-based vector drawing in effect. Check out LiTha-Paint, a promising new online vector drawing tool. The software is currently in alpha, yet is already full-featured and easy to use. LiTha-Paint steps beyond the paltry selection of Flash/VML/SVG online drawing tools, providing versatility and universality via HTML and JavaScript. Perhaps all this Web 2.0 business is worthwhile after all..

Update: Unfortunately, LiTha-Paint crashed due to lack of funds (welcome to the club). However, this particular post has now served its purpose by providing insight (via the comments section) into the wonderful world of mikons.com, a very inspiring online vector graphic site that enables users to create visual symbols and share them with a growing network of other vector artists. In their own words:

Welcome to Mikons.com, a new form of self-expression that connects people through visual symbols (personal tags). Our mission is to give you a fun and easy way to create these symbols that tell your story, let you decide how you want to share them, and use them to connect with people anywhere in the world.

Update [ January 10th, 2007 ]: Well, apparently LiTha-Paint is back in action and looking better than ever. Apparently, they found a way to make it happen — good for them! With any luck, this will be the last time I have to edit this post ;)

Read more

Lightbox + FancyTooltips Bug Fix

by Jeff Starr on Tuesday, July 25, 2006

For those of us enjoying the stylish functionality of Lightbox or any of its many incarnations, images "magically" overlay the window and unfold, revealing navigational buttons, image count, and of course the image titles.

For those of us enjoying the stylish functionality of FancyTooltips or any of its many incarnations, title and alt attributes manifest as stylish displays of CSS brilliance.

However, for those of us employing both features, there is a potential JavaScript conflict. This conflict makes it impossible for Lightbox to display the contents of title attributes associated with images. Thus, if you are employing Lightbox (or one of its many variations) and FancyTooltips (or one of its many variations), image titles will be missing from your Lightbox-displayed images. If this is the case, everything else (nav buttons, number display, close button) will display properly, including the "fancy" tooltips. If this sounds like your situation — missing Lightbox titles — we have good news..

Fortunately, the "fix" for this "bug" is relatively simple. Before getting to that, it is important to explain two things: (1) cause of the conflict and (2) verification of the conflict. Keep in mind that we are attempting to extrapolate from several specific scenarios to many possible configurations. So, if this article fails to fix your specific setup, hopefully it will provide insight toward an individually deduced solution.

First, let's examine the cause of the conflict. Generally speaking, JavaScript-based tooltip enhancement involves replacing title and/or alt attributes with author-specified "hooks" that enable scripts to function. For example, the FancyTooltips script rewrites all title="" attributes as fancytooltip="", thereby enabling the FancyTooltips script to recognize and act upon such attributes exclusively.

The problem is that once all of the title="" attributes have been replaced with script-specific hooks, Lightbox no longer recognizes them, making it impossible to display their contents. Hence the mysteriously missing Lightbox titles. To verify this, use your browser's "Save Page As…" feature to save an offline copy1 of a page that uses both Lightbox and FancyTooltips (or any other similarly conflicting scripts). Then, examine the source code of the offline copy and look for title="" attributes replaced by fancytooltip="". If you find that the title and/or alt attributes have indeed been rewritten, read on for the fix!

The Fix

Now that you hopefully understand the nature of the dilemma, it is time to completely eliminate the conflict.

Open your lightbox.js file and scroll down to around line #333, searching for the following:

// if image is NOT part of a set..
if((imageLink.getAttribute('rel') == 'lightbox')){
	// add single image to imageArray
	imageArray.push(new Array(imageLink.getAttribute('href'), imageLink.getAttribute('title')));			
} else {
// if image is part of a set..
	// loop through anchors, find other images in set, and add them to imageArray
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute('href') && (anchor.getAttribute('rel') == imageLink.getAttribute('rel'))){
			imageArray.push(new Array(anchor.getAttribute('href'), anchor.getAttribute('title')));
		}
	}
	imageArray.removeDuplicates();
	while(imageArray[imageNum][0] != imageLink.getAttribute('href')) { imageNum++;}
}

Now, near the end of the fourth line, replace title with fancytooltip. Then, likewise, near the end of the eleventh line, replace title with fancytooltip. You're done. Upload the file and check tooltips and Lightbox images. You should now be enjoying titles in your image popups and titles in your fancy tooltips. Note that this easy fix may be generalized to any set of similarly conflicting scripts. Simply determine the rewritten attributes by saving an offline copy and then search for & replace the offending values in the corresponding scripts.

This article is a work in progress. Please contribute any helpful information by leaving a comment below or via the Contact form. God Bless.

Footnotes

  • 1 In general, offline copies are very useful troubleshooting tools, as they represent the code after scripts have acted upon it, thereby offering a more accurate view of what the browser actually interprets.

Read more

Website Attack Recovery

by Jeff Starr on Monday, July 24, 2006

Recently, every website on our primary server was simultaneously attacked. The offending party indiscriminately replaced the contents of every index file, regardless of its extension or location, with a few vulgar lines of code, which indicated intention, identity, and influence.

Apparently, the attack occurred via Germany, through a server at the University of Hamburg. This relatively minor attack resulted in several hours of valuable online education. In this article, it is our intention to share experience with website attack recovery. This article is aimed at website developers, designers, and administrators.

Read more

Dead Letter Art Website Update

by Jeff Starr on Monday, July 24, 2006

A new Dead Letter Art website is in the works and coming soon. The new site enhances previous content with dynamic features and improved organization. The new site has also been updated to include more archived content, including ancient issues and special projects. Additionally, some keen Ajax functionality kicks the “fun” up a notch. Anticipated release date: September 1, 2006. Check out the old, sickly green website here.

Update: [ 02/01/07 ] — The new Dead Letter Art website is now in full effect! Check it out at deadletterart.com. Browse the infamous DLa Archives, chat live with the crew in the DLa Forum, or even leave a comment in the Guestbook. — You’ll be glad you did..

Read more

Native Sun Botanicals Website

by Jeff Starr on Monday, July 24, 2006

The Native Sun Botanicals website is now online. Native Sun Botanicals (NSB) specified a precise “look and feel” for their site, which is currently a “brochure” site that conveys some basic product information. As a botanical manufacturer/supplier, NSB strives to present a clean, refreshing image that is sophisticated yet simple. The site is designed to be standards-based, accessible, and optimized for search engines. As NSB develops its product line, the site will expand to incorporate database-driven, dynamic content. In the meantime, several key site elements will be added, such as business and contact information. Monzilla Media is providing complete website development, maintenance, and representation for Native Sun Botanicals, and looks forward to a mutually prosperous future.

Read more

Press Time

by Jeff Starr on Monday, July 24, 2006

After a few weeks of utter silence here at Perishable Press, it is time to post some fresh material. We have a few interesting — perhaps useful — articles coming up, including Website Attack Recovery, Lightbox/Tooltips Bug Fix, Even More Server Drama, and even a few posts covering recent events, tips, and other general nonsense. Things quiet down around here while we are working on new websites, but new content is always anticipated in between projects. We enjoy sharing insights and other news with readers whenever possible, and always enjoy hearing from visitors and guests. So, as the intense summer heat slowly boils us alive here in the Desert Oasis, we look forward to the imminent arrival of Fall, and all that that implies..

Read more

July 2006

by Jeff Starr on Wednesday, July 12, 2006

like fast and stuff with fingers splashing code, head spinz and and.
here again to share the now without reservation a calm deliberation
to accomplish what must be done. that’s all for now — gotta run..
..wake me up when september ends.

Read more


Attention: Do NOT follow this link!