Getting Dirty with Wordpress

Posted by Doug on March 01, 2009
Technology

I just got done with a long programming binge figuring out how to improve navigation on my NYC Facade blog. I didn’t gain any wisdom about how to approach this problem, but I have a few observations.

  • The wordpress documentation is nigh on the worst I have ever used. Contrast this with the PHP documentation. The latter has a comprehensive list of functions available, and for each there is a description of uses, caveats, related functions, code samples, and copious user comments (which often contain the exact solution), whereas the former contains an incomplete list which include fully-deprecated functions and scant examples, and not always the argument list.
  • Despite that fact, Wordpress has a lot of power under the hood. There are hooks and very simple ways of modifying almost any functionality. The behavior is very uniform, and you can harness various pieces to write almost any function.
  • As a result, there is very little wisdom I can impart to you, the google searcher or casual reader, that will make your wordpress theme or plugin easier to write. You just have to suffer, read the wordpress codex, and search for the random terms you find. Just be aware that you may have solved one problem that reveals another, although it is hard to tell you have, in fact, achieved your goal. (I suppose this is common in programming, but it bears repeating, since one always assumes the code was right the first time.)

The project I was working on was to add a new view to the NYC Facade blog so you can navigate by street or avenue. That is, suppose you want to view the buildings that are on Broadway; if you go to the right place, it will give the buildings on Broadway (or any other street), from lowest to highest street.

It wasn’t a fundamentally hard problem; the pieces are quite simple, really.

  • Tag each building with street name and street number (tedious, quite easy to do.)
  • Write code that will take in a URL and parse it to recognize the street name that is sought (using the Rewrite functionality as well as looking into the $_SERVER['REQUEST_URI'] variable)
  • Write code that will search the tags (Custom Fields) for that street name, and retrieve and order posts with that tag (using the add_filter function with posts_fields, posts_orderby, posts_where, posts_join, and request hooks).
  • Modify the theme to include the street names (using the get_meta_values and get_post_custom and similar functions).
  • Initialize so the various parts of the code gets run when a page is requested.

Unfortunately, uncovering all of that functionality was mostly an exercise in google searching and reading other people’s (completely undocumented, what else is new?) code, since the documentation was only a tiny help. I installed a pile of plugins, shoutout to Custom Field Taxonomies (the core of my plugin) and Custom Field Template (makes adding custom fields easy).

Now I can get back to adding my backlog of pictures to the site… and doing schoolwork. That, or decide whether to continue retooling navigation to separate the “building style” and “building function” tags from the frivolous ones. Offer your opinion here on that, if you dare.

No comments yet.

Leave a comment

WP_Big_City