Making a Data Portal With WordPress

I’ve been toying with the idea of making an open data portal for Mecklenburg, ala DataSF or Vancouver, for a while now, but I didn’t get around to starting one until last month. It’s pretty much done now, and you can see it here.

I say pretty much done because if you tried to make a comment right now our security device would likely give you a unhelpful 404. We have a security device tuned so tight it would report Gandhi to homeland security, and I haven’t gotten up with our security guys to tone it down yet. But it works enough to get the general idea.

I knew GeoServer would be the back end, because…well, it’s GeoServer. But I vacillated on what I’d use for the front end. I spend almost as much thumb twiddling time on that as I did making the whole thing.

I dismissed SharePoint early on. I don’t like SharePoint. SharePoint is an OK document management platform with aspirations. The selling point is it does just about everything. The problem is it does everything badly.

I thought I might take a stab at Drupal, which I’ve been threatening to do for ages. I saw a good Drupal talk at SELF that peaked my interest again. It’s powerful and complicated stuff. If I were to do a County-wide CMS today I would eat the learning curve and use Drupal. Using it for this project would be like squirrel hunting with a bazooka.

DataSF uses a modified version Pligg, which is a social publishing/rating site, ala Digg. It’s advertised as a “social networking CMS”, and I wasn’t looking to build one of those.

I finally fell back to trusty old WordPress. Most of what I wanted is just how WordPress works – posts, categories, RSS feeds, etc. But there were a few things I wanted to do that were a bit out of the ordinary (at least for how I usually use WordPress):

  • I wanted a rating system, ala DataSF.
  • I wanted a catalog page, ala Vancouver. And I didn’t want to have to maintain that by hand.
  • I wanted consistently formatted data and API links stored outside the normal post content.

All that turned out to be pretty easy. Here’s how I did it.

First, pick a WordPress theme you like. I’ve made my own WordPress themes before for the experience of it, but unless you’re a hardcore designer you’re probably better off grabbing a free one. I rather like Arjuna X, so I used it. When you use free themes like this, just make sure you leave a link back to the designer in the footer.

Now for the easy part – ratings. I liked the way DataSF let users rate data (note to self: may not like it so much after users actually rate the data). There are a number of WordPress plugins for this, but I went with GD Star Rating. It’s highly customizable and did exactly what I needed it to. Done.

Next I wanted a standard way to enter and present links to a WMS service or to a Geo API service or what have you. I looked at a number of options, but in the end I decided to do WordPress Custom Fields. It means a little more work for each layer, but there could be so much variability in each data feed it seems like the most logical approach. And most of the work is of the copy-paste-tweak variety.

So each post has its own custom fields for data links. Perfect.

Next I had to show those custom fields with the post. First you need to plan on editing any place a post might appear if you want the meta tags to appear there as well. Depending on your theme and what you want to do you’ll need to edit single.php at a minimum, but you may also want to edit index.php, archive.php archives.php, category.php, and search.php.

Basically you’re looking through what in WordPress parlance is “the loop”, and you’re specifically looking for the spot where the post content is dumped. It’ll be something like this:


<?php the_content(); ?>

Then you’ll want to add the a function called the_meta, either above or below the post content. I stuck mine at the top.

<?php the_meta(); ?>
<?php the_content(__('continue reading...', 'Arjuna')); ?>

The the_meta() function outputs the custom fields like this:


<ul class='post-meta'>
<li><span class='post-meta-key'>Curently Reading:</span> Calvin and Hobbes</li>
<li><span class='post-meta-key'>Today's Mood:</span> Jolly and Happy</li>
</ul>

Which won’t look very good unless you style it up a bit. I did something like this:


.postContent .post-meta  { width: 500px;  box-shadow: 3px 3px 5px #666;  -webkit-box-shadow: 3px 3px 5px #666;  -moz-box-shadow: 3px 3px 5px #666;  margin: 0 0 35px  0; }
.postContent .post-meta  li {  list-style: none;   margin-left: 0px; padding: 0;  border-style: outset;  border-width: 1px;  font-size: 14px; }
.post-meta-key { padding-left: 4px; margin-right: 4px;  display: block;  float: left; width: 150px; font-weight: bold; background: #fff }

Which gets you a much nicer table-looking presentation for the unordered list:

So there we have links to data feeds and ratings. Now I wanted a catalog page.

I created a new page template for the data catalog by coping another page template. To make a new page template in WordPress, you just make a PHP file with the template name at the top and it will show up in the page template list in wp-admin:

<?php
/*
Template Name: Data Catalog
*/
?>

I made a new page in wp-admin called Catalog using this template and left the page content empty. Then I snuck into the template page and did this where the the_content() would normally sit:

<!-- Catalog Table -->
<table style="width: 100%">
	<tr>
		<th>Dataset</th>
		<th>Category</th>
	</tr>
	<?php
		// SQL Call
		$sql = "select p.post_title, p.post_name, wp_terms.name as category
					from wp_terms
					inner join wp_term_taxonomy on wp_terms.term_id =
					wp_term_taxonomy.term_id
					inner join wp_term_relationships wpr on wpr.term_taxonomy_id =
					wp_term_taxonomy.term_taxonomy_id
					inner join wp_posts p on p.ID = wpr.object_id
					where taxonomy= 'category' and p.post_type = 'post' and p.post_status = 'publish'
					and wp_terms.name <> 'Blog'
					order by p.post_title";

		$results = $wpdb->get_results($sql, OBJECT);

		// Build table
		foreach ($results as $post):
			echo "<tr>";
			echo '<td><a href="/dataportal/' .   $post->post_name . '">' . $post->post_title . '</a></td>';
			echo '<td><a href="/dataportal/category/' . $post->category . '">' . $post->category . '</a></td>';
			echo "</tr>";
		endforeach;
	?>
</table>

The ugly bit of SQL is getting the post name, post title, and category for every post that isn’t the the category ‘Blog’ (in case I make a general blog post that I don’t want showing up in the catalog). The result is this:

And that’s it. Once I get our security device tuned I’ll take the Beta moniker off and start adding a new layer or API every week. Viva la open data revolucion and all that nonsense.

Is there nothing WordPress can’t do?

*Note once you start editing a theme like this, you’ve officially left the reservation. You won’t want to automatically pull up dates to the theme from WordPress, as they could overwrite your changes.

  • http://gis.lacounty.gov/egis Mark Greninger

    Hi there,

    The County of Los Angeles is preparing to launch a GIS data portal – see http://egis3.lacounty.gov/dataportal. It does exactly what you are talking about.

    I would recommend the MOre-Fields plugin as a better way to manage your boxes. It can standardize the addition of the fields you mention above, simplifying their management and giving you a lot more control. Just for fun I also add a geotag for each data entry so that we can eventually find data through a map!

    I’d love to discuss this with you. As well – I am designing a WordPress based site to maintain our points of interest and critical infrastructure – creating a single location to manage and maintain a very important data layer.

    Mark Greninger
    LA County Geographic Information Officer.

    • http://fuzzytolerance.info/ Fuzzy

      Wow. I really like your site. Are you planning on having data feeds (KML et al) or is it more like a clearinghouse?

      I haven’t looked into any of the WordPress field extensions, but I’ll have to check out the one you mentioned. What would make my life easier is if I could store a default value for fields, as most of them are slight variations of the same thing.

      I’d be curious to hear about the POI maintenance site and how you’re building that. I’ve been periodically pulling down GeoNames data for that. If you want to talk offline send me an email at tobin.bradley at gmail.com.

  • sam

    Very nice.

    But I am curious – why did you decide not to use a geospatial data catalog server such as GeoNetwork? It integrates quite well with Geoserver, OpenLayers, PostGIS and all the other standard things in an OpenGIS stack.

    • http://fuzzytolerance.info/ Fuzzy

      I’ve tried a number of GeoNetwork versions, with the last time being ~2.2. I’m venturing into opinion here, but beyond the various technical problems I’ve had with it (most of which can be blamed on our crusty FGDC metadata), I think it’s just too complex for non-GIS users to wraps their heads around. For certain use cases it’s probably the right tool, but for this use – enabling citizens to access the data and make their own mashups – the UI of GeoNetwork is just too unapproachable.

      *ducks*

  • http://www.psomas.com Craig Gooch

    Mark,

    I really like the LA County Portal. Nice summary content on each dataset page that provides flexibility of content. The category summary by theme and department is interesting.
    RSS also a nice feature to prompt new downloads.

    Craig Gooch
    Psomas

  • sam

    yeah, the out of the box geonetwork gui is a little too busy.

    UVA has put their own very nice, uncluttered interface on top of geonetwork and the rest of the usual stack. It’s still beta and the map does not always work (someone’s in midst of tweaking things?) but I like the guided search concept of their interface

    http://lat.lib.virginia.edu:8080/geonetwork/

    • http://gis.lib.virginia.edu Kelly Johnston

      Here’s the latest rendition of that UVA GIS portal:
      UVA GIS Portal

  • http://www.olc.com.tr Yurtdışı Eğitim

    It seems like a very good web site but my English is not good. But, I like this web site very much.

    By the way, Thanks for this information.

  • http://gis.lacounty.gov/egis Mark Greninger

    Hi there,

    We do plan on adding information about our services as well. We are currently in the final finishing phases for a number of services that will provide access to the County’s GIS data in nicely wrapped “packages” that will allow both GIS and non-GIS folks access to data and maps as services and functionality. For example – we have a geocoding capabilities – both the out of the box ESRI functionality, as well as “smart” geocoders that provide more direct access.

    Why am I moving toward WordPress for our catalog? A number of reasons…

    First – for anyone who has tried to edit metadata, the tools that are out there are pretty poor. FGDC compliant metadata is extremely complex, and having used ESRI’s metadata editor(s), they aren’t even a single editor – you have to edit both the FGDC and ISO versions. I’ve always been frustrated by the complexity as well. The basic information that you need from metadata are:
    1) What is the data? Basically the abstract in plain English.
    2) How accurate is the data?
    3) Any usage constraints (licensing, confidentiality, etc)
    4) Who created it?
    5) How do you use it? Generally this means a list of all fields and description about what they mean.
    6) Contact info.
    7) Any other pertinent info.

    A simple way to keep this information up to date is all you really need. WordPress and other blog software is designed to do this simply (and from many platforms). As well, it allows documents, pictures, source info, etc to be attached to the metadata. A related table can be posted as part of the dataset. A picture or a guide is worth thousands of words. On the site – note the thumbnails – it makes things easier.

    WordPress right now doesn’t allow the upload of .kml files directly – but in the future, I expect to replace the thumbnails with “live” maps that show the .kml file directly in the interface – so you can actually see the data before you download.

    Second – provide multiple ways to access this information. The fact that WordPress is a Web 2.0 enabler gives us capabilities out of the box that we could never build, and I don’t need to buy. The geo-portal software that ESRI makes is not free, and I doubt that it will integrate with Twitter, Facebook, Flikr, LinkedIn, and any of the other existing web-based sites that are out there.

    RSS and geoRSS are incredibly powerful for this – they provide automatic subscription capabilities that I, again, don’t need to develop – they come built in to WordPress. Have a question about the data – just write a comment and the author will be notified. Want to have a comment stream like on this site about the data – it’s built in. Want to edit your data information while on the road? I have an application on my Droid and my iPhone that let’s me manage the posts wherever I am. Want to see statistics about the people accessing the site – how many, etc? It’s all built in.

    Basically – we are taking a technology that is used by hundreds of thousands of sites – we don’t need to build specific GIS sites, so our cost of ownership is zero – we just update the data, and when cool new tools are created (for free) we just load them in!

    People who work with me know I’m a huge WordPress fan – hope you see why now!

    For the POI site – check out http://egis3.lacounty.gov/services_manager – that is (again) in final development, but you will get the idea …

  • http://ezinearticles.com/?Know-Secrets-of-Memory-Foam-Mattress-Topper&id=5033399 Khan Gee

    I was not aware of this great tip.

  • http://www.egitimyurtdisi.net yurtdisi egitim

    Good information, thanks for sharing with us

  • http://gis.lacounty.gov/egis Mark Greninger

    Hi there,

    Have you been working more on this? Has it launched? We’ve had a great response since we launched – about 300 hits per day. One question I’ve had it about the search box being able to search the metadata content? Have you found anything?

    • http://fuzzytolerance.info/ Fuzzy

      It’s live, and we’re getting some traffic. I think it’s mostly people just checking it out, but Jason Sanford did make a cool app for open data hack day that we posted to the web site. I haven’t had time to add much data lately – a tax reval and redistricting are devouring all my play time :) . The next thing I want to try is integrating some Google Fusion Tables data. It’s one thing to give developer’s links to make mashups with. With Fusion Tables the data could become a lot more accessible to laypeople.

      I don’t know of a good way to search through metadata with WordPress that wouldn’t involve serious hacking to WordPress’ search functionality. You could check out this old hack of a metadata server I did: http://code.google.com/p/metadata-navigator/

      It has a service that searches through metadata xml files on disk. It’s not a best practice kind of way to do it (Solr etc. would be much better), but for a low traffic site it works fine. I’d probably make a separate search box and have it link to an external metadata server.

  • http://www.weprintdirectforless.com kinkos

    I am really inspired together with your writing talents as well as with the format in your weblog. Is this a paid subject or did you modify it your self? Anyway keep up the nice high quality writing, it’s rare to peer a nice weblog like this one these days..

  • http://www.googleportal.com Anonymous

    Google Portal’da sadece kaliteli ve

  • http://www.logonow.com.au/logo-design-sydney logo design sydney

    A family member referred me to your resource. Thanks for the resources.