CollectaEDIT: Unfortunately, as of June 1, 2011, Collecta has shut down its real-time search service. But all may not be lost; Collecta has indicated that it plans to work with a variety of organizations (including United Way crisif relief projects) to open source its software.

A while back I wrote a post about the new Collecta widget for web and for WordPress, allowing you to embed Collecta real-time search onto your web pages and WordPress blogs. Since I wrote the post (on the day of the service’s release) Collecta has really taken off, and is getting a lot of great press.

Although I’m a big fan of Collecta (the service having been developed by, among others, my friends and former co-workers Christopher, Nathan and Matthew) I didn’t find the Collecta widget for WordPress very useful for my site. The reason for this is that the Collecta widget’s search parameters are defined on a per-site basis; you define them on the Widgets dashboard, and then wherever you place the widget on your site, those same search parameters are used. I wanted to be able to define my search parameters depending on the subjects of my individual posts – a reasonable demand for any blogger whose posts may span a variety of different topics.

The way I solved this was by using the Custom Fields functionality within WordPress. If I added a value for Collecta in a Collecta custom field when composing my post, a Collecta widget would appear in my sidebar using the search terms I’d defined. If I didn’t define a custom field for Collecta, that area of the sidebar would remain blank. It’s a bit of a hack, and Christopher and I plan to try to make something more permanent to address this need in the future, but at this point (as far as I’ve been able to find) I think I’m the only one who is using Collecta on a per-post basis within WordPress in this manner, so it’ll do for now.

And here’s how I did it, in case you’re interested in doing the same – fair warning, it does involve editing some code!

What you’re going to do is access the Collecta widget at by using some PHP that you put into the sidebar on the web page that renders your posts. On your single.php page (or whatever page it is that displays your posts) enter this code where you want your widget to appear on the page:

<?php include( TEMPLATEPATH . '/collecta.php' ); ?>

This accesses a file called collecta.php in your WordPress template directory where your widget code will be stored. Go ahead and create collecta.php, and within it, write these lines:

<?php if (get_post_meta($post->ID, collecta, true)) { ?>

<h3><?php _e(get_post_meta($post->ID, collecta, true)); ?></h3>

<iframe style="border:none;width:100%; height:480px;" src="<?php _e(urlencode(get_post_meta($post->ID, collecta, true))); ?>&alias=&nologo=false" id="widgetframe" frameborder="0" scrolling="no"></iframe>

<?php } else { ?>

<?php } ?>

This code places a Collecta widget on your post’s page if you have defined a variable for the Collecta custom field, or displays nothing if you haven’t. Note that you can turn on and off displaying the Collecta logo by using the “nologo” parameter, and you can also adjust the height and width of the widget by adjusting those parameters.

Save the file, then go ahead and start a new post. On your Edit Post screen, somewhat down the page, there is a box called Custom Fields, within which you can find an option to Add new custom field. Select Enter new, add a value of “collecta”, and then click on Add Custom Field.

Adding a custom field to WordPress

Click on – Select –, and choose the “collecta” value that you’ve just entered. Under Value enter the search terms that you’d like to have your post’s Collecta widget perform real-time search for.

Editing a custom field in a WordPress post

Write your post, save it, and view it – the Collecta widget should show up on your individual post using the search terms you’ve indicated, just as it does on the post you’re reading right now, where I’ve defined the search term as “Collecta”. Note that you can also search for multiple terms by using OR; for example, “Collecta OR widget”.

I hope this helps you get the very powerful Collecta real-time search widget onto your posts – please let me know if you have any questions or feedback, and I’d be glad to help you however I can.

Good luck!