23 Feb 2011 @ 4:52 AM 

Due to popular demand, I’ve devised a way to improve the built-in search engine of WordPress for my Davao food blog. WP’s default search isn’t very impressive — ok let’s face it, it’s downright disappointing, especially if your blog has thousands of posts already. (Good thing there’s an abundance of 3rd-party plugins from the huge community of WP lovers.)

Now, the need was to provide DavaoDeli.com blog readers with a search engine that could operate with filters. Such would allow for more specific searching, with the aim of narrowing down search results. In techno-speak, I wanted to inject more granularity into my site’s search engine.

Here’s how my blog’s new search form looks like:

Advanced Search @ DavaoDeli.com

Advanced Search @ DavaoDeli.com

My readers can now search for, say, Malaysian restaurants that serve beef barbecue in the downtown area, and be assured that the returned results have a high rate of accuracy. Of course, this was accomplished with some coding and re-keying of meta data for my existing blog posts. So here’s what I did.

The basis of the work is a powerful search plugin called Relevanssi, created by Mikko Saari. Once activated, it automatically takes over and replaces WordPress’ default search engine. As is, it’s a much better on-site search solution because it returns search results by relevance (not by publish date, which is the default behavior) and because of a number of other enhancements. What I really appreciate about this plugin is that it is rich in features and comes bundled with admin-configurable options that let you fine-tune your search requirements, plus a number of custom functions and even its own shortcode.

In order to create the search filters, I created two custom taxonomy types: Cuisines and Locations, which I assigned to work with normal posts. I’m already using the post categories for distinguishing establishment types (Restaurants, Eateries, Caterers, etc.); and the tags for identifying keywords for each post. Then, I categorized each post under respective cuisines and general locations in Davao City — good thing I only have less than a hundred posts!

Next — thanks to some helpful posts over at the WP.org forum — I defined a function that would automagically generate a <select> form control populated with <option> items that would contain the custom taxonomies. Here is that function (placed in functions.php):

function make_terms_dropdown($tax, $taxs, $taxonomies) {
	$args = array( 'orderby' => 'name', 'hide_empty' => true);
	$myterms = get_terms($taxonomies, $args);
	$output = "<select name='$tax' id='$tax' class='postform'>";
	$output .= "<option value='0'>All $taxs</option>";
	foreach($myterms as $term){
		$term_taxonomy = $term->taxonomy;
		$term_slug = $term->slug;
		$term_name = $term->name;
		$output .= "<option value='".$term_slug."'>".$term_name."</option>";
	}
	$output .="</select>";
return $output;
}

You might be wondering, Why not just use the wp_dropdown_categories() function, since it works with custom taxonomies? The problem with that built-in WordPress function is that, it spits out <option> items with values corresponding to taxonomy or category IDs (e.g., <option value="222">French</option>) and not names or slugs (this is what’s needed: <option value="french">French</option>). Neither the search engine nor your browser will have any idea that taxonomy ID 222, for example, corresponds to the custom taxonomy ‘French’ (under Cuisines). So, if I’d used wp_dropdown_categories() to create the filter — which I did, initially — the search wouldn’t return any meaningful results.

To quickly explain the function’s parameters:

  • $tax: name of the custom taxonomy type (e.g., cuisine)
  • $taxs: plural form of the custom taxonomy type — this is just for aesthetic purposes, really
  • $taxonomies: the list or array of taxonomies under the taxonomy type
Update: 24 February 2011

The original function above works only if your custom taxonomy type is non-hierarchical. If you use it on custom taxonomies that have sub-taxonomies (like in Cuisines), the result will be a flat drop-down list. So, I’ve revised the function to work with hierarchical taxonomies. To wit:

function make_terms_dropdown($tax, $taxs, $taxonomies) {
	$args = array('parent' => 0,
			'hide_empty' => 1,
			'hierarchical' => 1
		);
	$myterms = get_terms( $taxonomies, $args );
	$output = "<select name='$tax' id='$tax' class='postform'>";
	$output .= "<option value='0'>All $taxs</option>";
	foreach ($myterms as $term){
		$term_taxonomy = $term->taxonomy;
		$term_slug = $term->slug;
		$term_name = $term->name;
		$term_id = $term->term_id;
		$output .= "<option value='".$term_slug."'>".$term_name."</option>";
		$termchildren = get_term_children( $term_id, $term_taxonomy );
		if ($termchildren) {
			$padd = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
			foreach ($termchildren as $child) {
				$cterm = get_term_by( 'id', $child, $term_taxonomy );
				$cterm_slug = $cterm->slug;
				$cterm_name = $cterm->name;
				$output .= "<option value='".$cterm_slug."'>".$padd.$cterm_name."</option>";
			}
		}
	}
	$output .="</select>";
return $output;
}

There is still one limitation. I haven’t figured out yet how to make the list of taxonomy children to appear in alphabetical order. Ideas?

Posted By: Blogie
Last Edit: 23 Feb 2011 @ 04:52 AM

EmailPermalinkComments Off
Tags
 26 Jan 2011 @ 9:33 PM 

This is for those of you WordPressers who use YARPP (a.k.a. Yet Another Related Posts Plugin) and any of the excellent themes by WooThemes for your blogs. Especially if you’d like to spice up the plugin’s output a bit.

I use YARPP on almost all of my WordPress sites, and I’ve started tweaking the plugin’s output, inspired by another related-posts plugin that I saw on DavaoBase recently. That other plugin is called LinkWithin, and I like how it displays related posts with thumbnails. However, this plugin has almost no options, unlike YARPP, which has tons of it! (And I’m suspicious of LinkWithin’s way of inserting redirects — it’s as if, for whatever reason, they’re out to track the clicks…)

DavaoDeli.com screenshot

DavaoDeli.com screenshot

So, here’s something I’d like to share with those of you who’d like to keep using YARPP and display a thumbnail for every related post displayed on your blog posts. The screenshot here shows a post from my food blog — take a look at the bottom part (in the red square) with the “You might also like…” heading.

YARPP has a set of sample templates that let you control the visual output of the plugin. Instead of settling for the default settings, you can have a higher degree of control over how the related posts are displayed by using the YARPP templates. Simply copy one of those templates (located in wp-content/plugins/yet-another-related-posts-plugin/yarpp-templates) into your current theme’s directory, modify that template to your heart’s desire, then activate it via the YARPP settings page.

The custom YARPP template

Create a template file in your theme directory that will contain the related-posts code. For our purposes, let’s name this file yarpp-template-thumbs.php (N.B., for YARPP to recognize the template, it has to be prepended by “yarpp-template-”). The code I wrote for DavaoDeli.com is the following:

<?php /*
YARPP Template for use with post thumbnails
Requires WordPress 2.9+ and the WooThemes framework
Author: Blogie
*/ ?>

<?php if ($related_query->have_posts()) : ?>

<div class="relthumbs">
	<h5 class="relposts">You might also like...</h5>
	<ul class="relposts-thumbs">

	<?php while ($related_query->have_posts()) : $related_query->the_post(); ?>

		<li class="relitem">
			<?php woo_image('key=image&width=80&height=80&class=relimg'); ?>
			<span class="thumb-ttl"><?php the_title(); ?></span>
		</li>

	<?php endwhile; ?>
	</ul>
</div>

<?php else: ?>

	<p>No related posts at the moment.</p>

<?php endif; ?>

Line 7 above declares the start of the special WordPress Loop that calls the related posts (handled by the plugin). Line 16, on the other hand, is the one that displays the thumbnails. It’s a built-in function in all WooThemes.com themes with WooFramework version 3+.

YARPP settings

YARPP settings

For those of you who don’t use WooThemes, don’t despair. There is a YARPP template included with the plugin that you can use. It’s called yarpp-template-thumbnail.php. Just copy that template to your current theme directory, activate the template via the YARPP settings page, and make sure to follow the instructions contained in this page from the WP Codex.

(If you’re using a child theme, place the thumbnail-related WordPress functions in the child theme’s functions.php template.)

That’s it! I hope you’ve found this useful. :)

Posted By: Blogie
Last Edit: 26 Jan 2011 @ 09:33 PM

EmailPermalinkComments Off
Tags
 14 Jul 2010 @ 4:09 PM 

I’ve recently purchased a premium plugin for creating the mobile edition of my WordPress sites: WPtouch™ 2.0 Pro. I’d been using the free version of WPtouch (up to v1.9.16) and had been quite happy with it, so I decided to give the paid version a go. The premium version promised better features, you see. And, so far, I’m really satisfied with this plugin by Brave New Code (BNC). The $29 (Canadian) price tag seems really worth it, considering the broad functionality the plugin offers.

WPtouch doesn’t only give you added reach — by making your WordPress-powered sites available to the increasing number of mobile Internet users out there — but it also presents new opportunities for exploring the mobile platform for your online presence.

WPtouch Pro 2.0.5

When you install and activate WPtouch 2.0 Pro, you will have access to its dashboard (“WPtouchboard“), where you will be able to tinker with tons of tweakable settings. There are visual controls over the design and back-end aspects of your mobile site, such as input boxes for ad placements (currently supported: AdSense & Admob) and statistics tracking (you can embed your Google Analytics code). On the other hand, you have complete control over the plugin’s code — it is GPL, after all — so you can dive in and swim around the plugin’s internal workings all you like.

WPtouch Pro mobile themes

One huge difference between the free and paid versions of WPtouch is in theme management. In the free version, you only get one theme, and if you modify it, you’ll lose the mods when the plugin is upgraded. In WPtouch Pro, you can create your own themes and get to keep the mods & customizations across plugin upgrades. What’s more, BNC promises to ship more themes in the near future. But if you’re a theme designer, you can actually make use of the built-in skeleton template and create your own unique theme!

By the way, BNC is looking for theme designers who’re willing to contribute to the pool. If they ship your theme with the plugin, that’s going to be a good advertising opportunity for your services! I don’t know what other benefits you might receive — why don’t you go ahead and find out for yourself? ;)

What’s an iPhone app without cool, shiny icons? Another WPtouch feature is its skinning capability. You can choose from the 200+ icons that come with the plugin for use on your mobile site, or you can upload your own. You can also create an iPhone home-screen icon for use when you create a home-screen bookmark (BNC calls it “WebApp”), as well as a splash page that appears when you launch the WebApp. When you create a WebApp, your mobile site will be displayed in full-screen mode. No navigation, no address bar. Excellent for keeping your visitors glued to your site, no? (Now, all you’ll need is to make sure you got great content!)

One more thing I appreciate in the way BNC designed this plugin is that, WPtouch is made to be aware of other plugins in your WordPress installation. If there are conflicting plugins, WPtouch will let you know about it. Plus, there’s an option to disable plugins that are not compatible with WPtouch when your site is loaded on a mobile platform. On the flip side, it will also tell you with which other plugins it works best.

Posted By: Blogie
Last Edit: 26 Nov 2010 @ 01:01 AM

EmailPermalinkComments Off
Tags
Change Theme...
  • Users » 1
  • Posts/Pages » 355
  • Comments » 0
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Contact



    No Child Pages.

About Me



    No Child Pages.