9rules - The best content from the independent web.

Back To Blog

Written by Scrivs, Mike, and Tyme. Subscribe To RSS Feed

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?!

  1. 9rules Network » Blog Archive » Building the 9rules Network: Episode 1 Says:

    [...] 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 [...]

  2. Mike Stickel Says:

    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.

  3. The Useless List » Blog Archive » Building the 9Rules Network on Wordpress Says:

    [...] twork on Wordpress. An essential rwad for anybody, no matter if they use Wordpress or not. Read Episode 2.

    [...]

  4. Nik Steffen Says:

    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.

  5. Mike Rundle Says:

    Mike - If you only knew deep the rabbit hole goes. Star Wars references are everywhere in the code :)

  6. Michael Says:

    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.

  7. marcelfahle.com » Blog Archive » Neues bei 9rules Says:

    [...] auben, was die Jungs so aus Wordpress herausholen: Building the 9rules Network: Episode 1, Building the 9rules Network: Episode 2. Die [...]

  8. Websites Made Simple Says:

    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…

  9. Yet Another Dan » Blog Archive » Building of 9rules: Custom fields Says:

    [...] Building of 9rules: Custom fields Thanks to Brendan, I were reminded that episode 2 of building 9rules was “out”… This episode gives a short [...]

  10. Walker Says:

    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.)

  11. anton’s key dot com » Wordpress Articles you should check out Says:

    [...] 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 [...]

  12. All Forces » Blog Archive » Building 9Rules Says:

    [...] 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 [...]

  13. Marco Raaphorst Says:

    GREAT post! thanks!

  14. Rob Winters Says:

    Geat Sequel to a great original. Dont go all Godfather 3 on us with the next one will you. :-)

  15. 9rules Network » Blog Archive » Building the 9rules Network: Episode 3 Says:

    [...] 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 [...]

  16. Dutch Directions » Blog Archive » Hoe bouw je een weblog-netwerk? Says:

    [...] 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 [...]

  17. ThePodcastNetwork :: The BizBlog Show » Blog Archive » The BizBlog Show #07 - Colin Devroe Says:

    [...] s on how he created 9rules the backend for 9rules can be found: Building 9rules – Part 1 Building 9rules – Part 2 [...]

  18. Jazz Up Your Site: 28 Ways To Use WordPress Custom Fields « The Beaver Pond Says:

    [...] 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 [...]

Leave a Reply