Wordpress as CMS
After linked by Matt, I got some requests to share how I hacked up Wordpress for the Stanford Community Health Resource Center. So here we go. (Note: I'm sure there's cleaner ways to do a lot of this, and probably some of it WP can do intrinsically. I'd love feedback! And if you want any of the code, I'm happy to share.
A little background: I'm a medical student at Stanford, active in community health work, and the Community Health folks (who currently don't have a place for students to interact and share resources and information--boo, Stanford) got a mini-grant to get someone to develop an online community health center. Enter me, the general computer nerd of the class.
We wanted a place that could house a bunch of community-health related links, but primarily we wanted a site where students could post their community health projects, as well as their contact information and their community partner's information. The way it currently works, there's lots of students who have done community health work, but the incoming students have no idea who they are because the former are off doing rotations at the hospital, and don't really interact with the first and second year students. I had been reading a bit about Wordpress, and I've kinda taught myself basic (read: really crappy) PHP over the past couple years, so I figured I could probably figure out the code and
bend it to my will make it work for the community health site. Also: we didn't want to have to create ANOTHER login for students, because we already have 50 different ones at Stanford, and we thought people wouldn't use the site if they had to register, login, etc.
I did all the coding using NoteTab Light, a little freeware Notepad replacement. (I wish it had color coding, but oh well.) I did all the testing on my WinXP laptop, and I MUST recommend EasyPHP. It installs Apache, PHP, MySQL, and PHPMyAdmin for you, it's free, and it just plain rocks. (Note: if you use the same DB from your local php install onto your server, you have to change the WP_OPTIONS TABLE SITEURL to the online URL, AND change the WP_OPTIONS TABLE'S HOME to the online URL. It took me forever to figure out why this wasn't working.) Also, thanks to Stanford IRT for hosting the site. Enough of that. Now on with the show.
I guess I'll just go page by page here and try to highlight the changes I made.
- index.php (template file)
I wanted to use a static greeting if there was no query, so I basically made an if() statement that checks the URL, and sees if there's anything after index.php. If there is, it displays that dynamic content in THE LOOP. Otherwise, if the URL ends in index.php, it displays the basic "greeting/welcome" content.
- All the Wordpress posts are individual Community Health projects, and are all included in the main category, Projects. However, on this main page, the template calls makes the header "[CategoryName] Community Health Projects." To keep this from sounding weird, I added an if() statement that if the category is just "Projects," don't display the [CategoryName].
- We extensively use the post meta-data fields as information specific for each project (my project as an example), and because I somehow didn't ever find the metadata plugins (maybe they weren't out when I first started), I made some really nasty code that makes the table and links certain data with certain other metadata URL fields. Also: note that the "View all of XX's Projects" is just a search query for the full person's name.
As far as the categories and subcategories go, I didn't want people to be able to visit any of the main categories, because that wouldn't make a whole lot of sense, so when it displays a category list, it has a bunch of if statements that say if category==Funding, change the style a bit and don't hyperlink.
- It was also vitally important that meta-data be searchable, so I hacked the search code to get it to work, although I'm sure it's not all that pretty. (I'd really like to see this option be included in vanilla versions of WP, if possible. (Just a checkbox in one of the options panels?)
- For the list of students page and the list of community partners pages, I used the get_custom plugin. (Much easier that way.) Thanks to Scott for helping me with it, I had a couple brain farts.
- The resources page is basically just pulling all the links from Wordpress's links manager, and organized by category. Used nicetitles for links.
There are two users of the system, an administrator will full access, who can approve posts, and a basic user who can post new projects and edit old ones, but anytime they click "save" it turns the post into a draft. I'll show screenshots using the administrator and then just show relevant differences with the basic user login.
add or edit a project page (there's no edit basic or edit advanced, because I always wanted control over publishing, and always wanted the meta-data input stuff to show up):
- the edit screen:
Options: turned off most of the fancy-stuff as well as comments.
- basic user screens (note most options aren't available, instructions slightly different)
and the edit screen: