She’s Geeky – Tour of WordPress template code

There were 20 or so people at this talk, including non-programmers and programmers wondering if they should install WordPress, and bloggers and admins already familiar with WordPress. We did a round of introductions:

* Graphic designer interested in what degree of control she could have over a WordPress blog.
* Benay, running a blog connecting seniors with caregivers.
* Collie, looking for help with a WordPress upgrade on a complicated blog. Where is community to find help or pay someone to help? (Collie and others: you might try Heather L. Sanders. Anyone else have recommendations?)
* Person who installed WP to force herself to learn more code. Curious about plugins. Which are most useful?
* Terri – uses WP at her job for blogging, thinking about running her own for personal use.
* Nadine – Installed WP for other people many times. Does a lot of troubleshooting.
* Laura – Has installed and messed with WP many times. Wants to create a template from scratch.
* Stephanie – has an HTML site. Might want a blog.
* Olya – is a blogger. sometimes has language barrier while troubleshooting.
* Estella – artist, craisin.com.
* Crystal Marie – adding a blog to her existing web site. Looking at WP and Drupal.
* Beth C – Loves WP. Would like to do more customization.
* Michelle – Is a coder
* Vee – Blogs for her company. Knows HTML.
* Min – Uses MoveableType, is curious
* Karen M. – Thinks there might be entrepenurial opportunities with WP
* StephanieBamBam – Personal blog

I’ve been using WordPress for several years and administer a group blog. As part of my job, I do tech support for bloggers who run into template problems and quite a few of them use WordPress, so I look at a lot of different templates and help people troubleshoot. (The other part of my job, I munge data, write back end tools and infrastructure-y scripts in Perl, Python, and PHP in an aspiring codemonkey way.)

I started out by saying that WordPress was blogging software that you can either use on wordpress.com, or can download for free and install on your own server or web host. You will need an account somewhere and need to have it clear in your mind that you’ve got a username and password for that server account. In that account you’ll be making a folder where you install WP, and then you’ll have an administrative username and password for the WP admin and blogging interface. You may need to pay attention to this in order to change file permissions and make your theme files writeable if you want to edit them from the Theme Editor web interface. This tends to confuse people who aren’t used to web hosting. Also, some people use web hosts which have one-click installs or who install WP for you and then charge to upgrade or maintain it.

We looked at the files and folders in a WP installation. There was some discussion of how you move files around and edit them. (Either from the command line on your server, from the admin interface for theme files, or with FTP; you can download the WP files, and extra themes and modules, to your computer, then upload them to your web host.) It’s a good idea to just look through all the folders, so you know what’s there. You may want to read through the wp-config file. But most of what people deal with is in wp-content, in the themes and plugins folders.

We then looked at the WP administrative dashboard, a bit at Widgets, and then at the Appearance menu and the Theme Editor. I said that editing code in the Theme Editor window sucks. While it’s great for making quick changes, I recommend you edit the files in a text editor that will color code the code and indent it nicely, like vim or Textmate. You can pass code back and forth with other people by putting it into pastebin.com, which will also color code and indent it nicely. Also, it’s amazingly helpful to print out all the template code, and mark it up with pen, and see which bits you can understand; or at least understand more or less what it does.

I explained briefly that anything that looks like a command with parentheses after it, like get_header, is a function and you may need to look for it in functions.php to figure out what’s happening. We looked at index.php for a little bit. It is helpful to read through it. You should be able to mark what is header, what is the content (including “The Loop” which will cycle through your posts), and what’s the footer.

The WordPress codex is your friend. Here’s some great starting points:

* http://codex.wordpress.org/Using_Themes
* http://codex.wordpress.org/Stepping_Into_Templates
* http://codex.wordpress.org/The_Loop

Take a look at your sidebar.php file, header.php, footer.php, and page.php for individual post pages.

At some point, I mentioned the site to look for and download WordPress Themes. You can specify whether you want fixed width or floating; one, two, or three columns; and other parameters such as the main color. It is often best to start with a fairly popular theme.

Keep track of customizations you make to the theme you pick, because at some point you will want to upgrade or change it. Make backups.

There was some discussion of plugins as well. All in One SEO Pack (which sounds a bit evil, but which is great since it makes your URLs a bit more human readable as well as search-engine-friendly) had good recommendations. Stats, Sitemaps, and various Flickr or photo plugins were mentioned by bloggers at the session. On the group blog I co-administer, we had written some code to pull in a list of all our plugins onto a static page called “What we use”, which has come in handy many times when we want to recommend useful plugins to other people. (Whoops; when I tried to show this off, I found that our recent upgrade to 2.7 had broken this code.)

The post template plugin was mentioned for its usefulness and for being able to pick a post or a page and “template-icize” it. This sounded intriguing!

Someone else mentioned that people should be aware that new plugins might break other ones and if you run into trouble, uninstall some plugins and see if that fixes the problem.

Someone else asked if there are good books for learning WordPress theme development or php. I don’t know about books, but php.net is fantastic, and the WP Codex is quite good. The Codex is also editable by its users, so if you use it a lot, make an account, log in, and fix any documentation that’s wrong when you figure out a solution. I also recommended blogging your template or code problems or posting on forums, and then posting the solutions to those problems when you figure them out. This is hard to do sometimes, but the more of us who do it, the better.

When I mention IRC at this conference my general impression is that people aren’t using it that actively and many people don’t know what it is. People who were techy or coding at all or playing on MUDs or smoething before the web, or before about 1995 or 96, know what IRC is. People who learned their stuff or got involved with online worlds after that, it’s much more hit & miss. In any case, I continue recommending people try IRC and hang out in channels on freenode that have to do with the tools or languages they’re using. Here’s some explanation & guidance on IRC and WordPress. Lurk for a while, pick up the culture of the channel, and you might be surprised you can actually answer other people’s questions: when I do this I tend to feel better about asking questions myself.

At some other point I mentioned MAMP again. It’s very handy and easy to install, if you want to run a local web server off your Mac in order to develop and test. While I was doing this hour long talk, at least two people downloaded and installed MAMP and WordPress and got it running on their laptops.

I enjoyed this session! We didn’t go all that deep, but we covered a lot of ground and people seemed energized by the ideas and possibilities. If you were there, thanks for coming, and let me know how your project turns out!

She's Geeky

Related posts:

Lost my mind in PHP

The last few days I went a little nuts thinking about PHP and rewriting a very horrible messy script. I’d write something, make it work, write a little more, break the first bit, go back to look at the first bit and find that I couldn’t understand my own code that I’d written the day before. I ended up throwing it out completely, waking up the next morning and writing the entire thing in a nice, neat, correct way. Within a day and a half, it worked, and is readable. The most important things that improved this sad blob of pointy-looking things and regular expressions were:

– decent formatting, without slacking off! Equal sign in vim, you’re my pal.

– abstract things out into functions. Do it twice? think about making it a function.

– But don’t always, if it’s going to make a simple thing confusing. Keep it clear!

– Name the functions logically.

– Really think about naming variables so that the code makes sense when you read it.

I struggled with understanding what the hell I was doing in the first script because, I swear, everything was named $tag and $another_tag and $taglist and $tagfeed[] and $tag->tag until I was lost in a maze of taggy little passages, all alike. How very, very embarrassing! If you ever see that code, please burn it!

Now all the variables have very logical names so that everything makes sense. Doing that made me understand what I was actually trying to do — much better than I had understood it before. Everything became clear and fell into place.

The php.net pages are truly awesome. I did struggle for silly amounts of time trying to figure out what the hell to do with strings. Like do I want egrep, preg_match, substr, strstr, or WHAT? (I usually end up with preg_match since I know perl regular expressions reasonably well.) But I appreciated php.net/function pages very much. The explanations make sense, there are examples, the lists of related functions often lead me to stuff I want to know, and the comments by other users *completely rock*.

Meanwhile, I read PHP Sucks, But It Doesn’t Matter on codinghorror.com, and the entire crazy comment thread that is half computer science “real programmer” snobs, half even realer programmers rolling their eyes, and half people who know they are the 3rd half and who are Microsoft types (in other words, weird aliens from other universe). All I can say if any of these guys calls me a “script kiddie” I will enjoy kicking their teeth in!

Bike? I don’t need your bike! I can kick your ass with these here training wheels! Snobs.

My thingamajig now reads tags in from de.licio.us, parses them, decides what kind of thing they are, pulls out different kinds of posts, and builds lists of post titles by subject grouping and source in a somewhat complicated way. Then it writes all those lists out to a jillion little static files which will be cached… everything will be so much faster and more polite to the delicious servers this way. Joy!

Related posts:

De.licio.us API and SimpleXML

I spent some time today looking at the de.licio.us API and writing bits of php with SimpleXML. Both of them are very easy and clear to use. I tried a bunch of the examples in the de.licio.us api docs to think through what it was possible to do with the queries. I really like de.licio.us, and hope it… well, hope that it stays pure. It’s so nice and clean, it makes sense, it’s not all crapped up with junk all over the page or the interface. Maybe a little more since the redesign, but it was fairly restrained.

This article by Matt Biddulph shows how to do some interesting stuff with de.licio.us data using Python, libxml2, tagsoup, and the Redland RDF toolkit. Backing Up Delicious with PHP, mySQL, SimpleXML, and Ajax also looked like fun to try. That was all way too fancy for what I needed to do today, but I’m keeping it in mind for future tool-building or experimenting with my personal del.icio.us account.

I had an annoying and frustrating interlude of realizing I needed to download xcode onto my new hard drive, downloading it for like 2 hours, going off in the meantime to 2 other machines I have accounts on to see if I could do what I wanted there while waiting for xcode, doing half of it (had php5, did not have other stuff I needed!), realizing slowly that I was in an endless labyrinth of nowhere quite having all the tools or access that I needed, and going back to my laptop in disgust. Also, I’m on a Mac and out of sync with the several different linux servers I have accounts on, so am always switching environments and remembering things that need to be tweaked.

I wonder how much time other people spend fiddling with their development environment? Or having to set it all up again after some crash or computer loss? I’ve noticed that even the holiest sounding super-experienced people who act like they’re perfect about these things still spend a good amount of time saying “Oh, wait…” as they flail around, hit dead ends, and so on. That makes me feel a bit better about what happened today, when my stupid xcode download finally finished, wouldn’t install, puzzled me for another frustrating 20 minutes until I realized my laptop was running an older operating system than it was before my HD crash. Ran around looking for CDs to upgrade. Failed to find them. Dammit! Downloaded older version of xcode. Now everything works! Tomorrow I will make the php all nice and make it do what I want… then stuff it all into a Drupal module.

Related posts:

Joy of unit testing

(From about 2 weeks ago, late at night)

I was just vaguely napping and realized I was still thinking in my sleep about the php code I had just been writing. Though I barely even know php at all, it wasn’t that hard to just guess at it because it was mostly like Perl. My thinking in Perl is a bit stuck. Today with Oblomovka I wrote out what I wanted my program to do, then he started writing tests. At first I didn’t get it that the tests didn’t run actually in the program. My thinking was inside out. I thought I’d run a bit of code, then run something that tested if it did it right, or that error/die statements would be sprinkled around. But as I saw what Oblomovka was doing it was like a light went on and I felt like everything I’ve written has been incredibly sloppy! Works fine, tells you if it doesn’t work, but was like wearing shoes instead of making a road. Or the other way around.

It was really fun to write the very simple tests and then figure out how to send it the simplest possible thing to fake it out so that the tests would pass. So for example if you were writing a simulated ball game, you would not start by simulating a baseball game. Instead, you might vaguely sketch out what happens in a game. Then, you’d write a test that goes like, “Does a ball exist? If not, FAIL.” You would watch it fail. It’s supposed to. Then think of the smallest thing it needs to do to pass. Your program would then merely need to go, “Oh hai. I’m a baseball” and the test would pass. You’d write another test that goes, “Is there a bat?” and “Is a baseball coming at my bat?” As you write fake bats, balls, and ball-coming-at-you actions, the baseball game starts to take shape. All the tests have to keep passing. The structure of how to build it becomes more clear, in a weird way. This isn’t quite the right analogy. I can’t quite get into the way of thinking and end up just hacking quickly on ahead. But for a little while, I felt the rightness of this way of doing things.

Technorati Tags: , , ,

Related posts:

Geek culture changes

I have gone from working in places where I have about 4 computers on my desk plus root everywhere to working for Silicon Valley startups where people bring their own laptop to the job and no one has ever seen a terminal window before. Most of the bloggers I know (and support at work) deal with their blogs and web hosts entirely from ftp desktop clients. And at someone else’s fairly technically oriented workplace that shall remain nameless, just the other day, I over heard two people talking:

Q: So why do you people use those window things? And why are they always those black screens? Is it like, to look like The Matrix or something?
A: Um, well, I think it’s just a culture thing. It’s old school. Or something.

As I was reading through scads of comments on php.net and the forums on phpWomen.org I thought about how some people post stuff like “and here’s how I like to indent my code“, with examples. Actually I like reading that stuff and when it’s super simple, all the better. Yet I never post my own notes and habits and cheap unix tricks, because I’m embarrassed they aren’t super whizz bang hackery but are just my thoughts on vim vs. vi, or notes on how to change my csh prompt to be different colors. Why don’t I post on that stuff? I might start. How many times over the years have I gone to look something up and ended up on shallowsky.com? A ZILLION TIMES! (Thanks Akkana!) I’m not posting for programmers – actually I might be posting for the bloggers who are only just trying out their new shell account and want to know what it can do.

So about geek culture changes. Aside from people who don’t scream when they see a command line, what about the deeper culture? I was reading Rebecca MacKinnon’s post Silicon Valley’s benevolent dictatorships and thinking back on all the pocket-watch-toting, vest-wearing, oddball sys admins I’ve known. MacKinnon (heavily quoting Danny O’Brien) describes how U.S. geeks put a lot of trust in technology and the internet:

we have come to depend way too heavily on a small number of Internet and telecoms companies to conduct the most private and intimate details of our professional and personal lives. As long as those companies have values aligned with our own and are run by people we think have integrity, we don’t see a huge problem. But what if the values cease to be aligned or political circumstances change?

While I agree with MacKinnon that a company’s leaders are important, I suspect that a lot of power right now is in the hands of sys admins, quite often the actual benevolent association or intersection of hippies and hacker-anarchists who inhabit university basements and run the backbone of the net. They’re also powerful in determining what happens. I think about what is happening and how it’s partly about a cultural shift in what people think the Internet is – rather than it being something you get your hands dirty in, that you play around with, where you bother to go read the RFCs even if you’re not writing them… something that people like you are *making*… you shift it and its policies – you are its state and government – to something you consume or use that is run by far-distant giant corporations (whether they are trustable or not is not the point.) I wonder about younger generations of sys admins. Are they DIY in spirit – and have they been activists? That matters too – along with privacy policies which in theory are set by legal departments and corporate heads – because the people who will implement that stuff often care and have influence.

Related posts: