The following is a transcription of an audio recording from Aaron Holbrook’s WordPress CMS Presentation
Speaker 1: So we have Aaron Holbrook tonight. He came up from Chicago. Aaron is from McHenry and runs A7 Web Design. He actually serves clients all over the globe, which is pretty awesome. Aaron also runs, he’s organizing WordCamp Chicago this year and runs the north western suburban WordPress group. Give it up for Aaron.
Aaron: So, WordPress is a CMS, dammit. I run into this a lot, where people come to me, clients, bosses, stakeholders. They say, “Well I heard that WordPress is just a blogging engine, right?” No, it’s a lot more than that and I am going to get into that. I’m Aaron Holbrook. You can follow me on Twitter, @aaronjholbrook. I sometimes rant about WordPress, and I run 87 Web. A little bit about me. I’m a Chicago PHP web developer and Wordpress fan since about 2005 when I first started getting into it. I do a lot of freelance web development and I own and operate A7 Web Design which is a web development, WordPress agency. I am a father of two awesome boys, a two year old and a nine month old. My wife, I love my wife and I love video games and I am a huge geek. That’s me in a nutshell.
A little bit about my background. For quite a number of years, I was a web master for a hospital, and I ran their website. In that time, I went through way too many proprietary awful CMS’s and I got to develop a sense of what a good CMS is, and what a not good CMS is. After going through a couple of really bad proprietary CMSes, I decided WordPress has finally reached this stage where they came out with 2.9, with custom post types to do everything you need to do on WordPress. So I rebuilt the hospital website entirely on my own, and I saved the hospital hundreds and thousands of dollars in doing so.
Currently, I have clients around the world. I’ve done countless things. I can’t even think about how many I’ve done. Quite a few plug-ins for the last two point releases, including the one right now coming up, 3.6. I’ve been a core contributor to WordPress. I also built an automation script called WP Builder. If you know what Dash is, it runs basically anytime you need to set up a new local WordPress environment to do a new project, it downloads the latest version of WordPress, downloads your favorite plug-ins, and installs them all. It sets up a database, it basically gets all the grunt work out of the way so you don’t have to. It runs in about 45 seconds; so it does about five to 10 minutes of work, it cuts it down. Since I am doing a lot of themes and projects, it’s nice. Check it out, it’s completely free and it’s open source, so up on GitHub. Check it out, I like it.
Like Brad said, I founded and run the Northwest Suburbs of Chicago WordPress Meet Up Group. I’m actually leading an organization of Word Camp, Chicago this year, so I hope you all come. A quick overview of what I am going to talk about. We’re going to talk about what WordPress is, really. I’ll show some examples of it being a little bit more than a blog. Then talk about what is a CMS, what does that entail, what makes WordPress a CMS. Getting into things like custom host sites, custom taxonomies, metadata, and then new relationships.
So everybody says that “WordPress is just a blog, right?” Well, no not really. WordPress can be whatever you want it to be. WordPress powers about 15% of the top one million websites. I don’t think that would be the case if it couldn’t handle being more than just a blog. So of the sites that do use WordPress, only about 10% of them use it just as a blog; 90% of them use it just as a CMS and a blog. About 64%, 65% use it completely as a CMS. Okay, so let’s take a look at some examples.
This is a site I did for a client in Australia. It’s a social wine club. There are a couple things right off the bat. So we’ve got wine, we’ve got vineyards, we’ve got regions that vineyards can go into. All these are custom content types so what we do, we register a post type or a content type as wine and then we can add any type of wine that we want, so we can manage that. Then we can attach metadata so we can extend out what that content type really is. We can say what region it is in, what vineyard it belongs to, what the phone number of the vineyard that it belongs to is. You can have pictures of the wine or of the vineyard. So moving on, you can also have vineyards as a content type. Again, you can attach metadata to that content type; so you can see there is a lot more you can do than regular blog post with just the title and a block of content.
Another site that I have done is Sassy Hong Kong, which is a blog for women in Hong Kong looking for fashion advice or where to eat. They wanted a directory system so they wanted a place to be able to write reviews and write information about local shops, local bars, restaurants, that sort of thing. So what we did, we built this directory using WordPress, ` as the management system for it. With that, you can see that, it might be a little bit small but there is address information and telephone and websites. There is featured images as well as Google Maps and you can actually rate them. You can rate each establishment. So the hospital website that I built there is location information. There is a location directory and with that you have phone numbers, you have addresses and you have images and you have maps and stuff like that. There is a lot of meta information that goes along with that content type of location.
Even with my own company’s website, so a portfolio, a portfolio that was a content type that extends off of WordPress and makes it an actual content management system. Another cool thing that we’ll talk about a little bit later, but relationships really increase the complexity in the amount of cool things you can do, in taking it to the next level. I have a content type of portfolio items, so I can list them through this website and here’s what I did. But I also created a content type of testimonial, and the reason that I split it up, so I didn’t just have the testimonial on the same page as the portfolio item was so I could use the testimonial on other areas of my website without the actual portfolio; and then you tie them together and you can display them together or you can separate them out. So having relationships with your content types, enhances what you can do.
Some examples that are not my own, I did not actually do BBC America, although I wish I had. They can manage shows, and videos, and schedules; movies is a good examples as well. All the different things, are just a content type. So they can easily add a new theme, just by adding new theme, add a featured image, some metadata information about the theme.
So CMS, what is a CMS really? A CMS is a way to manage content easily. It’s a lot easier to use a CMS than to hardcode all the html. While when you turn it over to a client, they are not going to be able to do that anyways. A CMS allows end users to manage the content effectively and easily. What does it look like? It looks like the regular WordPress interface, with a couple of extra meta boxes. Wow, the contrast is really blown out there.
So the three elements that make up a CMS, in terms of WordPress, are custom post types, custom taxonomies, and metadata. Custom post types came into, I guess their nomenclature came into being, because everything stored in wpposttable, and they are all defined by the post type column, so that’s where you get post type. Even though you might have lines, and that might be your content type, it’s still a post type. So it’s confusing because you may have a page that is a post type. Once you understand it and get your mind around it, it’s pretty simple. So the default types of post types are a post, a blog post. You can also have pages which are static content. Attachments which are images and media files as well as revisions, which are past versions of other post types so of a post or page of your custom content. And then [nav menus] that you are familiar with under appearance are actually a default post type.
So, some examples of what could be a post type, basically anything you can think of, wines, people, humans, actors, bars, restaurants, anything you can think of that you really need to manage in this type of fashion, you can create as a post type. So that means WordPress is a CMS for anything, really.
So let’s make our own. To create our own, all we have to do is first add a hook into a net which I won’t get into because it’s outside the scope of this talk, but a hook is a way to have code run at a certain time when the rest of the site is [inaudible 10:53]. So, we run this function, and all we’re doing its registering this post type. So register post type, and then we give it a name, not that people are going to see but what we’re going to use internally and WordPress is going to understand. So we can’t use spaces. We could use capitals, but could we?
Speaker 1: Yeah, but don’t.
Aaron: Yeah, don’t use capitals. I wasn’t sure or not; so don’t use capitalize. So then we’re going to the next parameter. So the first parameter is the name of the post type we’re doing. The next parameter is an array of arguments and this is the bare bones, minimum. You’re not going to get a lot with this, but just for an example of how to define it, this is what we do. There are more options of it in that link and I tweeted the slides for this talk so go to at aaronjholbrook at twitter and you’ll see the slides and I’ll post them at the end. For the bare bones minimum, we need to label it so it will be on the administration screen we can see what post type we’re going to hit. We want to set it to public, because we want people to see it and we want to be able to manage it. We also want to set an archive. This isn’t required but if you want to view a list of all the post types or all the content that you’ve added, you’ve got to set the has archived [to true].
So we’ve registered. Next step, save your permalinks. I am going to say this a couple times. Anytime you’re changing your post types or your taxonomies or you are doing anything that could potentially affect how WordPress is looking for things via the URL, you want to go in and save your permalinks. That helps WordPress understand what is happening again. It refreshes everything. So save your permalinks. It’s under settings, permalinks. Then, if you’re using post naming you’ve definitely got to save your permalinks.
Speaker 3: Do you have to do that every time?
Aaron: Just when you create a new post type; so how I went through and added. The question was, do you have to do that every time? So I added a new post type and now I have to save it; otherwise when you go to view it, and the url, you’re pretty permalink like slash City Guide, it’s not going to know what to look for yet. So you just have to do it the first time.
Now that we’ve added the post link, we can add some content so we can go, typically unless you change it in the parameters, your new post type is basically going to appear right above the [inaudible 13:28]. When you go to it, you see this is our label, you can go add new and like I said, this is bare bones so we’re only going to have the title and the heading box, but we can start adding custom title. So we add a title and we add some stuff. Now we can go and look at it from the front end of the website.
You can see this url/City Guide, that’s what I was talking about with the permalinks. If you hadn’t set the permalinks, it wouldn’t have known what you were looking for at that address. This is the archive [library]. This is going to show, remember I said has archive is true. I want to be able to see all the different posts I have done. If you have not heard of WordPress Template Hierarchy, write that down, and go look it up. That is one of the biggest thing that I found when I was doing WordPress development that made me really kind of get what WordPress was looking for at a certain time. Once you understand that, the template hierarchy is really important, because it’s basically the logic that WordPress follows to find a certain file. So in your theme, so it’s looking for city guide, what’s it going to look for first? First it’s going to look for archive, and then dash, and then whatever the post type is. In our case, it’s going to be city guide. If that file doesn’t exist, now it’s going to look for archive.php. If that file doesn’t exist, than it’s going to go back to index.php.
So it follows this, if this exists use that, if not, use that. But that allows us, for each post tag, to use a completely different lay-out. So I can use a different lay-out for City Guide than I would for wines or vineyards. When we click through to an actual post item, or in this case a city guide item. I don’t know why I went for Moby Dick for city guide. It was late, okay? I was kept up late by a two year old. When you click through that, it’s going to look for single dash, your post type name. If it doesn’t find that, it will fall back to single.php. Then what does it fall back to if that doesn’t exist?
Aaron: Which one?
Speaker 2: Single.php. Index.
Aaron: So it always goes from most specific to least specific, falling back to index.php. So we can see our content. So that is a custom post type. You can create anything you want. Let’s move onto to how do we group those posts? How do we organize them? How do we filter them? That’s where taxonomy is coming into play. So a taxonomy is a way to group things logically. So, default taxonomy that word press ships with; category allows you to categorize posts. Tags, which is ;like categories, but a lot more free flow, you can add them on the fly, and they are not structured in any way. And link category which, I included it because it ships with it but we deprecated links, so there is not really a point to discussing it.
So custom taxonomies, some examples would be like genres or brands, types of beer, types of wine. We are going to talk a little bit more in a minute but you can also do sub-types. So you can say “Okay, I am going to have a red one or instead of red, a Merlot, or a Cabernet.” You can really get specific with however specific you want to get. First, we want to register to create it. Again, there are a lot of arguments. There are a lot of ways to customize it. Again, I am going very bare bones, but we’re going to call it function register taxonomy, we’re going to name it, and I am going to use a category as a name, but I am not going to use the built in category, because that one is already a tie in two posts. In this sense, I don’t want to use the same category. Technically, you could. Like if you had your City Guide and you also wanted to tie it in the same as your posts. You can totally do that; I’m not going to because I am keeping it clean. City Guide category and then I want to attach it to the City Guide post type that I created. This is really important because the taxonomy should be attached to a post type. You could also attach it to default posts or pages. So you could actually add a category for your pages. Then we want to be able to say that it is hierarchal. That’s exactly what I just said about having a red wine and having a Merlot be a child of the red wine. So it actually has structure, you can have descendants or children. Then we want to set some limits for it. So categories is the plural. The singular is category.
Save your permalinks. It’s important. If something isn’t working on your site, and you’ve just done something in code, go save your permalinks before you freak out. I can’t tell you how many times I’ve done that. I’m like “404! What did I do?” So to add a term; a term is an item in a taxonomy. You go under City Guide and you can see we have the categories link and that just opens up the regular categories. I am sure you’ve seen this before on your posts. You can just add it with the name and the slug and it will automatically make the slug based on what you add. That’s where you can also, since set hierarchal, we can set it up here for that term as well.
So, the listings for taxonomies, again, looking at the hierarchy, it’s first going to look for taxonomy dash what your taxonomy dash what the term is your looking at. If it doesn’t find that, it’s going to fall back to taxonomy dash your taxonomy name. If it doesn’t find that, it’s going to go back to taxonomy. Then again, if it doesn’t find that, it will go to index. So that will display, even though, ignore this, that’s not part of that. It will display what posts are tagged with whatever term you’re looking for.
So we’ve looked at how to define custom post tags. We’ve talked about how to create a taxonomy. The next step is metadata. Metadata really allows you to transform a simple title and content block into something so much more. It allows you to attach bits of different information to each post type. Now, actually creating metadata fields is a lot of work and it’s way beyond the scope of this talk. I thought I would, instead of walking you through all that code, it’s pretty hefty. You have to add a meta-box then you have to hook into when it saves and pass some [inaudible 20:57] and stuff. I’ve done it myself amazingly and it’s way easier to use something else. I am going to start from the bottom.
Advanced custom fields, I’ve heard good things about. I haven’t used it myself. I prefer not to use it because this plug-in you add all the metadata through the WordPress interface. It makes it easy, but, it comes at a cost of all the information about the metadata is stored in the database. So every time the WordPress loads, it first has to call the database. It has to call that information out of the database. I prefer the top two, which actually hard code everything, so all that metadata is pulled and it doesn’t need to be pulled from the database, first. But if that works for you, and if you’re not building a huge scale site then it doesn’t matter.
WP Alchemy I used for about a year and a half. It’s fantastic. It’s by a guy, his handle is called fartinspace. It’s up on GitHub. It’s really, really good. It’s not a plug-in but it is code you pull into your theme, and it allows easily define input fields and metadata. Until I found SuperCPT, super custom post tag, by a guy named Matthew Boynes who I met at Word Camp, Providence. This thing is so slick. It allows you to define a custom post tag, define taxonomy, and define a metadata within five line of codes. It does a lot of the labor work for you and it’s really brilliant. One of the cool features of about this, is that all of the metadata that you find you define, you can actually call from the helper function. That helper function will remember what metadata this plug in defines and just call that information; because there is other metadata stored with the regular post, like your revision. What else is stored with it? Like the last saved date, lap dates. Stuff like that you don’t really want. The stuff you do want, like vineyard region or the phone number and website, just that stuff we want to grab and we want to throw into an array or a variable, this does that. I got to toot my own horn but I actually wrote that function. But it’s really cool. He’s a really nice guy. I really like SuperCPT. I’ve used it in a couple of projects, and it’s pretty cool.
So looking at some examples of metadata, I had scrolled down a little bit and this is a meta-box. You can see these are fields that I have defined that you can enter for every custom post type. Then taking it a step further, I was talking a lot about relationships. This allows you to create relationships like one to one or one to many, or many to many relationships between different custom post types. An example would be, that wine site I was talking about. If you’ve got a wine, a vineyard, and a region, and we want to show the wines that belong to a vineyard on the vineyard page, we need to somehow relate the two. So WordPress knows, Okay Suttonhouse has the red and the white and it belongs in the Napa Valley region. You can’t do that unless WordPress knows how that works. So I use scrupulous post to post plug-in, and all you do, so you install the plug-in and then you define the relationships in your function dot php file and you can say wine belongs to vineyard and you can also say vineyard belongs to region. And on the edit screen, there are little plus signs on the right hand side and you can just say, Okay this wine belongs to the Purple Hands in Barosa Valley. So it’s pretty cool. It allows you to take your WordPress CMS to the next level. In a nutshell, I think WordPress is a pretty damn awesome CMS. Thanks!