Recent Blog Entries
Building the 9rules Network: Episode 2
Written by Colin Devroe on January 18, 2006
The response from the last episode was overwhelming. Thanks to everyone that commented, emailed, instant messaged me, and linked back to that post from your own sites.
Last time we discussed how I used mostly smoke and mirrors to build our data structure using WordPress. Things didn’t change much for quite sometime, but I thought I’d jot down how we used custom fields to store the meta-data we needed for each member, rather than hacking WordPress’ fields in order to store our data.
Custom fields to the rescue
WordPress allows for unlimited and even duplicate custom fields per post. For every project I’ve used WordPress for, custom fields are probably the feature I use most. For more information on using WordPress’ custom fields, I suggest reading the Codex page of “Using Custom Fields“.
At this point in our story, still late-Spring or early Summer 2005, we only stored 3 custom fields per member. We needed a place to store the member’s URL, feed URL, and Author name(s). Instead of utilizing one of WordPress’ existing fields, and using it improperly, we opted to use custom fields which makes it easy to keep this data up-to-date per member.
Getting the data I need out of each custom field is not only easy, but convenient at any given time in my code. Typically when Mike Rundle turns over a comp to me, he will ask “Hey homie, is there a way to stick the Author’s name in there? Not sure how hard that would be.”. I left in his misspelling of homey, for authenticity purposes. He stopped asking that question rather quickly when I replied: “At any point, on any page, at any time, I can put any members data wherever I’d like, without even thinking of ‘how to do it’”. That was all he needed to hear. But how do I pull it off? We’re working with WordPress created data, am I in THE_LOOP? Am I using a plugin for the_post()? None of the above, here is a simple function that allows me to snatch the then existent custom fields we were using.
function siteInfo($id='') {
global $wpdb;
if ($id && $id != '') {
// Per site info
$member_author = get_post_meta($id, 'Site owner', true);
$member_rss = get_post_meta($id, 'RSS', true);
$member_url = get_post_meta($id, 'URL', true);
$siteInfo = array(
'id'=>$id,
'url'=>$member_url,
'rss'=>$member_rss,
'author'=>$member_author);
} else {
// There was an error
$siteInfo = array(
'error_number'=>1,
'error_text'=>'No site_id was given');
} // end if $id
return $siteInfo;
}
At any point in my code, I can run this function and retrieve the data I need for any of our members, and should I accidently not give it an $id it will end up giving me a definitive error that will be immediately recognizable.
As a side note, whenever I’m building datasets based on any number of variables, I typically return them as multidimensional associative arrays. This makes it much easier to check for validity, for referencing later in your code, and just making the data generally available at anytime you need it.
You might be asking where we stored the title, or name, of each member’s Web site. We stored this in the title field, so I typically had the $id and $post_title at any point when I would need to use siteInfo(). That is why that particular function does not need to fetch the title, or name, of the Web site - because I already have them in memory at that point.
The possibilities are endless
For those of you that feel limited using WordPress, and feel that just about any other CMS will work for you better, remember custom fields. It really makes the possibilities endless, per post, for what you’re able to accomplish. Over at TheUberGeeks.net, we use several custom fields to create our featured posts. We have custom fields such as; featured_art, featured_caption, album_art, cover_art, and a few others that allows us to display more than the typical content that WordPress would allow out of the box. Om Malik of GigaOm.com uses custom fields, by the assistance of a few plugins, to control his “Featured Post” of the day. Most of these examples are non-complex and generally easy to duplicate, should you use WordPress for your site and you’d like to extend your capabilities.
In our next episode, which I call Revenge of the Server, we’ll get into how I used our page views to build our cache of member data (it was my only choice at the time), and how Media Temple came to our rescue. The smoke and the mirrors had to be replaced with viable solutions at some point, right?!
January 18th, 2006 at 9:29 am
[...] he next Episode. Next Episode: Using WordPress’ custom fields to build an empire. Episode 2 is now available.
Posted January 15th, 2006 in The Network [...]
January 18th, 2006 at 10:36 am
It was only a matter of time before the blatantly obvious Star Wars references showed up.
Nice write up though. Definitely digging the power of multi-dimensional associative arrays.
January 18th, 2006 at 11:06 am
[...] twork on Wordpress. An essential rwad for anybody, no matter if they use Wordpress or not. Read Episode 2.
[...]
January 18th, 2006 at 11:09 am
Wow, thank you so much for this brilliat write-up. Your experiences with Wordpress have already helped me an immense amount, and I am looking forward to the next episode.
January 18th, 2006 at 1:06 pm
Mike - If you only knew deep the rabbit hole goes. Star Wars references are everywhere in the code
January 18th, 2006 at 3:31 pm
Thanks for the nice write up. I don’t know much about custom fields, but will know about them in the near future. I’m actually learning more about wordpress and blogging than at any other site.
See! You can learn things by reading blogs.
January 18th, 2006 at 4:41 pm
[...] auben, was die Jungs so aus Wordpress herausholen: Building the 9rules Network: Episode 1, Building the 9rules Network: Episode 2. Die [...]
January 18th, 2006 at 11:19 pm
9rules Network - The Making
Current episode: Episode 2: Power of Custom Fields It’s big, it’s black (or at least used to be), it’s got an organic type logo, it’s The Making of the 9rules Network. After a few nudges by some fans, Colin starts…
January 19th, 2006 at 3:31 am
[...] Building of 9rules: Custom fields Thanks to Brendan, I were reminded that episode 2 of building 9rules was “out”… This episode gives a short [...]
January 19th, 2006 at 10:55 am
Absolutely Michael. I have to say that “limited” is something I’ve never felt since migrating to Wordpress (for various blogs) a couple of years ago. With a little PHP knowledge, such a brilliant plugin mechanism and the Codex bookmarked, pretty much any brick wall can be demolished. (And I’ve lost count of the number of Wordpress plugins that utilize custom fields.)
January 19th, 2006 at 6:06 pm
[...] f your needs, perhaps these articles can help you. Building the 9rules Network: Episode 1 Building the 9rules Network: Episode 2 Entry Filed under: Miscellaneous [...]
January 19th, 2006 at 9:20 pm
[...] th the read if you are a web developer. Link: Building the 9Rules Network: Episode 1 Link: Building the 9Rules Network: Episode 2 No R [...]
January 20th, 2006 at 11:40 am
GREAT post! thanks!
January 22nd, 2006 at 12:12 pm
Geat Sequel to a great original. Dont go all Godfather 3 on us with the next one will you.
February 12th, 2006 at 12:17 pm
[...] ng the 9rules Network: Episode 3
by Colin Devroe comment below
As I mentioned in Episode 2, I wanted to tell you how I used our page views to build our cache of member [...]
March 5th, 2006 at 4:27 pm
[...] us om zo’n avontuur in WordPress te beginnen… Toen wees Marco me op een aantal artikelen op het 9Rules-netwerk. Het 9Rules-netwerk, voor degenen die dat nog niet wist [...]
March 20th, 2006 at 8:18 am
[...] s on how he created 9rules the backend for 9rules can be found: Building 9rules – Part 1 Building 9rules – Part 2 [...]
April 1st, 2008 at 8:52 pm
[...] site publishers may want to display an author info box on each writer’s posts. Store the author name and other data in custom fields and [...]