Andy Skelton?

Yeehaw, it's another blog! I'll try and stick to topics relating to WordPress and Automattic, Inc. Of course, nothing here is edited or approved by Automattic or any other entity. These are my views. Your mileage may vary.

Useless Code in WordPress Themes

This won’t matter to most WordPress.com users but I removed a bunch of unreachable code from almost every template file in Sandbox. The logic of this should be understood by all theme authors so that you don’t waste your time maintaining useless code!

This is the crux: at the top of the main loop, have_posts() and is_404() are mutually exclusive. If we have posts it is not a 404. If it is a 404 we have no posts. If is_404(), template-redirect.php sends us to 404.php (index.php if that’s missing). Thus have_posts() will never be false at the top of single.php, archive.php, etc. unless a plugin is doing something very wrong.

Does your theme provide an else handling in every loop of every template file? If it does you’re maintaining code that will never be executed by the server. Do yourself a favor and execute it–with an axe.

So why are so many themes testing have_posts() at the top of the loop? The bundled themes have been recycled without enough critical thinking. Probably the documentation needs a comb-through. I’m generally too busy thinking up new stuff to worry about all that old stuff. Bad Andy. Will somebody step up?

Adapting the veryplaintxt theme for use on a Swedish language site, I see that has the same problem. Are you planning an update to that one too? It’d be nice to know, since I’d like to keep the translation as close to the original as possible.

Very nice. The asides css is pretty smooth too. Gotta say I love this stuff. It took me a few minutes yesterday to make a zoom/contrast layout version of your Kubrick skin. Can’t wait to have more time to do some serious damage.

One question about the category linking (good catch Scott)… I’m not terribly familiar with WordPress.com treatment of categories and tags but it looks to be one in the same unless I’ve just seen a bad example. Any plans to address tags so that they’re rel-tag compliant? Seeing how you’ve been sticking to microformat compliance so far, it would make sense of course.

I use Ultimate Tag Warrior which is an absolutely wonderful and powerful plugin. The downside is that it has no rel-tag compliance mode which uses the + sign as spaces and points to your own archives instead of technorati. So I hacked it to bits a few versions ago to get it to do what I wanted… it’s nice and rel-tag compliant while linking back to my tag archives but it took away some of the built in functionality to see the intersection of tags as well as combinations of tags. I never went and cleaned it up, now there’s been two new versions since, hehe.

Anyhow, any specific tagging plans I should know about before locking myself up with the new version of UTW for a while?

Eventually it would be super nifty if someone came up with h*whatever creator interfaces for WP with drag ‘n drop positioning of elements. Styling is amazingly simple, but there’s little to be done when the elements aren’t in the order you need them in.

Then again, I’m trying to convince the K2 guys to add php overlays to the roadmap so some of us can develop small mods for frequently asked for modifications from less experienced folk. So yeah, I’m insane.

But, on topic, I agree with Anders to a certain degree… everything is so incredibly easy to style with CSS alone that it almost seems wrong having no control over the hard-coded stuff (I have workarounds in mind for that but for the sake of skinning I don’t even want to come close to touching the core). So I propose something silly, but possibly useful… any hardcoded text elements could be replaceable via the admin interface or just a simple file for all I care. Have the current text configured as default for the variables but replaceable if the user wishes… just the text, not any markup. Then, no more hard-coded text. That make any sense? Or is that where you draw the line and say just edit the damned php? lol

Oh, my second proposal was just an conversation item. I completely agree on the fragility. Just throwing out ideas in the open. 🙂

But I think any :before, :after and generated content issues could be fixed with some DOM Scripting for browser that doesn’t suport the pseudo-selectors. I will investigate it, the support and implications.