Picture of the Day



Atticus enjoying some shade, originally uploaded by mwalters.

Can’t blame him, it was in the mid 90’s.



This post is part of the Picture of the Day Series for 2009.

Custom Fields in WordPress

While working on a site recently, a common problem was run into using WordPress as a full fledged CMS. The issue was needing to have multiple content areas within the same Page. For a developer (front end or back end) this typically isn’t an issue, even inside of WordPress. Since the content area allows you to insert custom HTML a developer can just flip to HTML view and position things on the screen how they see fit. However, that’s not always a viable option when handing over content management to your client. The client may not have the knowledge nor the desire to learn HTML on their own. This can leave the theme creator in a difficult position. Luckily WordPress provides Custom Fields as one way to help get around this predicament.

Custom Fields in WordPress can be used for many things:

  • Assigning images to Posts (featured image or thumbnail)
  • Serving as a data source for content to be loaded via Ajax
  • Providing multiple content areas for a Page (custom sidebar for instance)

One “gotcha” of using Custom Fields to solve this issue is that the size of the input area is limited. There are possible ways around this limitation, but they’re outside the scope of this Post so we’ll save that for another time. Putting that all aside though, they can definitely help get you to where you need to be.

Custom Fields have two components, “Name” and “Value.” If you’re of the developer mindset, think of it as a simple key-value pair. You can have multiple identical keys even on the same Page/Post. Once you have used a key once it then becomes available from the select box on future Posts/Pages, making it easier to reuse custom fields for similar operations on other pages. You can use get_post_meta() anytime the WordPress core has been loaded for the Page view and you have access to a Post or Page ID.

Let’s take the third example, providing multiple content areas for a Page, as an example in using Custom Fields in your theme. We’ll be using get_post_meta(). Here are some basic steps to move towards putting this all together:

  • Edit a Page you would like to add a unique sidebar to
  • Add a custom field name of “sidebar”
  • Add any content you would like to the value field
  • Save your Page
  • Create a Page template file inside your theme directory
  • At the top of the template file add this PHP code:
$sidebar_content = get_post_meta($post->ID, 'sidebar', false);

Some explanation:

  • $post->ID feeds the primary key of the Post or Page that is being displayed by your theme
  • ’sidebar’ is the “Name” or key for the custom field you added to your Page in the WordPress Admin
  • false tells get_post_meta() to return an array of key-value pairs for the requested key. If set to true, it would return a single result as a string.

From here, adding the extra content to your Page template is fairly simple. Perhaps you have a sidebar container you would like to place it into. You could use this PHP code to do that:

foreach ($sidebar_content as $content) {
  echo '<p>' . $content . '</p>';
}

The above example would loop through each Custom Field you had added with the name ’sidebar’ and would display its content wrapped in a paragraph tag.

Using this overall approach you can now add custom content areas to specific Pages or expand upon the idea to perform other customizations such as easily formatting a thumbnail for a Post/Page. By using a custom field for the thumbnail, you can then format the thumbnail differently based on the context it is being displayed in, as opposed to just inserting it into the copy area of the Post/Page. For instance, if you wanted to wrap the copy around the image when displaying it as a full Post or Page you could do so, but if you wanted to display recent Posts on your homepage with the copy blocked to the right of the image, that now becomes easy as well (it’s just a matter of html/css markup at that point).

Picture of the Day



The tough life, originally uploaded by mwalters.

Life is hard as a dog, what can I say?



This post is part of the Picture of the Day Series for 2009.

WordPress File Monitor Upgrade

I’ve released an upgrade to WordPress File Monitor, my plugin for notifying you when files are added/changed/deleted from your site.  A few small bugs have been fixed and there is now an option to choose between checking file timestamps or using hashes of the files.  Anyhow, check it out, let me know if you have problems with it :)

SnipIt.me Upgrade

Added comments to SnipIt.me using Intense Debate.  So you can now comment on photo’s, code samples, and URL’s (via the preview method instead of the redirect method).  They’re hidden by default to keep the interface minimal, they can be displayed by simply clicking the View Comments link near the bottom.

Picture of the Day



potd, originally uploaded by mwalters.

Little did I know when I adopted a dog from the SPCA that I would be getting a gargoyle as well!



This post is part of the Picture of the Day Series for 2009.

For Three Decades …

… the world has had to put up with me now.  I declare that 30 is the new 21.  ;)  Woot.

BlackBerry Curve 8330

BlackBerry Curve 8330Roughly 9-10 months ago, I switched from my iPhone to an enV2 with Verizon. AT&T’s coverage was just horrible, basically making my iPhone an iPod Touch with an expensive monthly subscription cost. Anyhow, the enV2 served me well, but I got to where I was needing to keep a closer eye on some things (WordPress Easily, some work stuff, etc) so moving back to a real “Smart Phone” was making sense. Enter the BlackBerry Curve.

I have previously used a BlackBerry. I always remembered the BlackBerry as being a consistent and reliable device, but using the Curve I’m starting to realize just how much I really enjoyed the style of phone. It really is a well thought out device, from push email to the tactile nature of the keyboard, from how stable the platform and applications are to the new store for BlackBerry apps. So far I’m really enjoying the device. I won’t go on and on with a long review, but here are the basics as I see it, in no particular order:

Pro’s:

  • Verizon service. It’s extremely rare that I see No Service. I actually can’t remember the last time a call dropped because of my service or that I was unable to place a call.
  • Keyboard: I’ve said for a long time that this is a key advantage of the BlackBerry over the iPhone. I really like the iPhone as a device, and the keyboard logic on it is superb. But the easiest way to explain it is on the iPhone I constantly had to watch my typing to see if it was going to catch/fix the typos I would surely make. On the BlackBerry, I just don’t make the typos to begin with.
  • Applications: The BlackBerry has REALLY improved in this realm since the last time I used one of the devices. Here is some of what I have installed:
    • GMail (the application version) – This works well for checking my multiple gmail and google apps accounts, though I do wish I could control the update interval, but I really like that it is able to keep conversations grouped, etc.
    • Pandora – Wow … over a cell phone’s internet connection I can’t believe how well this works. Quality enough to make an audiophile happy? Probably not. Quality enough to make me happy? Yes.
    • Google Talk – It’s not often that I need to IM over the BlackBerry, but this is a great real time client for when I do need to.
    • BlackBird Twitter Client – It isn’t going to stun you with its looks, but it has the core functionality I want when I’m using twitter on the go. I’m usually only checking updates on the go when I’m bored, I can quickly skim with Blackbird. It also works well for sending updates and catching @replies even from people I’m not following.
    • Google Maps – Not sure this needs explanation. It’s a great app and works well.

Con’s:

  • Trackpad/Scroll ball: They really should have stayed with the thumb wheel in my opinion. It is tolerable, but I preferred the thumb wheel.
  • Keyboard: Weird this is mentioned in both places right? It’s a little on the small side, but I find it hasn’t been a problem and I’m adapting quickly.
  • Camera: I was a little torn how to rate this. Listing it as a Con may not be appropriate … but it’s a cell phone camera so keep your expectations low.

Overall, I would say my feelings about the device are positive. I’m really liking the new applications that are available and I’m pretty sure I’m addicted to the CrackBerry once again ;) Not to keep comparing it to the iPhone, but that’s really the only device worth trying to compare it to … in my opinion, the BlackBerry is still the Gold Standard to be beat. The iPhone rocks, but they still need to work some things out if the BlackBerry userbase is a target audience (which it may not be and that’s cool, there’s enough room for both products).

WordPress File Monitor

I’ve released a new WordPress plugin called WordPress File Monitor.  Essentially, it keeps track of what files are installed in your WordPress install (or site) and watches for files being added/deleted/changed.  One catch is that it does rely on WordPress being able to load in order to do its work.  So if the malicious individual totally brings your site down, or removes WordPress from loading somehow, it won’t work.  However, a lot of the hackers out there have gotten to where they like inserting code into your WordPress pages, sometimes code that you can’t even see because they make it only show up to search engines.  This plugin will help protect you against that by alerting you when the changes are made or a file of theirs is added to your system.

Currently for tracking changes to files, it is just comparing the modified date of the file.  Eventually I hope to make this more robust.  Another note is that there is an option to exclude paths from what is being monitored by the plugin.  If you use a plugin like WP Super Cache, it is highly recommended that you exclude its cache directory from being scanned.  Otherwise you will constantly be notified of changes made to the cache files.  In a future release I hope to make it auto detect WP Super Cache and not monitor those files.  I also would not set it to scan more then every 15 minutes or so.  Otherwise you run the risk of the plugin scanning your entire site every time someone visits your site, and that’s unnecessary load on the server.

Additionally, keep in mind, this is currently a pre-release beta.  So if you find bugs, please let me know on the plugin page.

One final note … you should always be aware of what is on your site.  This plugin will not replace you doing periodic scans of your site to make sure files haven’t been added or changed.  I make no promises whatsoever of its ability to catch all changes to your site.  In the end that responsibility rests with you and you alone.  So keep an eye on your site, and hopefully this plugin will help you with that job.