Learning WordPress both as blogger and developer

I recently started attending meetings of the East Bay WordPress Meetup Group, including today’s fun WordPress Plugin Hackathon, hosted and presented by Website in a Weekend‘s Dave Doolin and TechLiminal‘s Anca Mosoiu. (That’s pronounced “muh-show-you”, as in, “WordPress is easy and fun. Here, let Mosoiu!” Sorry, Anca, I just couldn’t resist ;-) .) I learned some cool stuff about hacking WordPress (in a good way), and also got some advice for beginning bloggers: “you should blog every day!” And despite my newbie-ness, I was able to contribute a bit by helping others debug their PHP a little.

Well, I don’t know if I’ll achieve every daynor that I really ought to! But let’s see if I can get myself in some kind of a habit, here. If you look at the dates on my posts, it’s obvious I’ve been a little sluggish getting into the swing of things. I will try to post more about what I’ve been up to lately. Let’s start with what I learned today!

Plugins, shortcodes, and custom fields. I much enjoyed Dave’s walk-through of a very simple plug-in. We first set up a development environment on our local machines. Easy as: 1. An apache/mysql/php stack (I already had WAMPServer running on my PC); 2: An editor (they recommended the Aptana Studio IDE which I installed for this occasion yesterday since I don’t do much development on this machine, but to be perfectly honest I missed the intro to using Aptana if there was one, and didn’t really feel like getting up to speed, so I just did this simple task in WordPad, which was perfectly adequate); 3: locally installed a test WordPress blog, rather than unleashing development code on this blog! Creating a simple plugin was pretty straightforward. You just create a PHP script in your wp-content/plugins directory, and it magically appears in the plugins page of your WP dashboard to be activated like any other plugin. Of course, it doesn’t do anything until you add some code.

Dave walked us through a simple plugin to add some special navigation to individual posts, for example if you have a series of posts on a single topic and you want to have links to the other posts in the series. It consists of three simple elements. First, you use two custom fields (a standard WP feature found on your Edit Post page) to indicate which other posts you want to link to as “previous” and “next”; each custom field has a name that the plugin will recognize, and a url for the post to link to. Then you write a PHP function in the plugin script that will recognize these custom fields and build some HTML containing links to those URLs. It shouldn’t produce any output to the page; instead, the function just returns the HTML as a string. Finally you just need a shortcode so that you can invoke this function from your blog posts. I’d heard of shortcodes before but this took the mystery out. They’re just a simple name that invokes the function you added to the plugin script. I named my shortcode “post-series”, so I just type that right into my post in square brackets (“[post-series]“), and it magically invokes the PHP function and is replaced by the HTML the function returns. And voilà!

Screenshot of plugin output from WordPress Hackathon

Fun stuff! Thanks, Dave!

This entry was posted in Web development. Bookmark the permalink.

4 Responses to Learning WordPress both as blogger and developer

  1. Anet Dunne says:

    Wow, Sharon, you are a GREAT explainer! My head was buzzing with all the information from David Doolin’s Plugin Intensive at the East Bay WordPress MeetUp, and your blogpost really helped sort it out. I don’t think we got to Aptana at all because so many of us needed help finishing our LAMP stacks. I know for sure that none of us would have succeeded getting the plugin working without your EXCELLENT debugging skills. What an eye! One of your many talents. Thank you so much for being there. BTW, I think Anca is considering an “Advertising on WordPress” event. Would Katchinga be an appropriate element for that discussion?

    • Hi, Anet! Wow, thanks for the kind words! (In fairness, I didn’t get mine working either, until Anca applied her keen eye. It’s fun when everybody’s helping each other!) Great to meet you yesterday.

      As to your question, it depends what’s meant by “Advertising on WordPress”. I look forward to hearing more! I could certainly present something about Kachingle if it turns out to be appropriate for the topic.

  2. Dave Doolin says:

    Sharon, thanks for the mention, really appreciate it!

  3. Pingback: DIY WordPress - World's Shortest Plugin | Website In A Weekend