Computers & Technology

Fun with CSS in WordPress

I just had an email exchange with an old friend and fellow web developer (and WordPress user) regarding some techniques for CSS trickery on home pages in WordPress themes. Up until this week, I had been running a version of my theme that just featured brief excerpts of articles on the home page. I was doing this by brute force in PHP, truncating the post text with the substr() function, and then cleaning things up using the strip_tags() function, which removes all HTML tags from a string.

It got the job done, but as he and I were discussing, it wasn’t pretty: it stripped out the “dangerous” stuff — that is, unclosed HTML tags (cut off during truncation) that would have screwed up the formatting of the rest of the page. But it also stripped out desirable styling (bold, italics, links) and paragraph breaks.

The ideal situation would be to have a way to show just the first two paragraphs of each post, retaining all of their original formatting. Of course, WordPress has a feature to handle this: if you put a <!--more--> comment tag in your post, your page template can truncate the post at that point, with a link to the single-post page to display the rest of the content. But I’ve never liked having to put that <!--more--> into my posts. I want a completely automated solution.

And then it hit me… this could be done with CSS. It took a little trial and error, but I came up with the following:

#content .entry p,
#content .entry h3
{
display: none;
}

#content .entry h2:first-child,
#content .entry h2:first-child + p,
#content .entry h2:first-child + p + p
{
display: block;
}

A few things to note:

  • This assumes that your entire loop is wrapped inside <div id="content">...</div>. You may need to come up with a specific ID to use just for this block in your index page, and be sure not to use that in your single-post page, or your posts will never appear in their entirety.
  • This also assumes that you’re using the WordPress convention of wrapping your posts in a pair of <div> tags with the attributes class="post" and class="entry" (though technically, class="entry" is the only one that matters here).
  • Your post title should be in an <h2> tag, immediately following <div class="entry">.
  • The first definition may need to be extended to include other HTML tags you want to hide on your index page. In this example, it’s only hiding content that is inside <p> or <h3> tags.
  • If you want to hide every HTML tag except the ones you explicitly specify, you could change the first block to #content .entry *, but keep in mind that will also remove styling like bold and italics, and it will remove links. Probably not what you want.

The specifics may vary depending upon how your WordPress theme is set up; I just know that with the way mine is set up, which pretty closely follows standard convention, this CSS worked to get the index page to list the posts and only show the first two paragraphs of each. (It also retained the images that I embed at the start of each post, and also retains any embedded video from YouTube or Vimeo, since — at least the way I insert them — those are not wrapped in <p> tags.

Note that all of the HTML content for each post is still loaded by the browser — we’re just using CSS to tell the browser not to show it on the page. This is not going to help with performance; it’s strictly aesthetic.

Sponsored Links

“All in” is right

Today, according to banner ads and discussions from the likes of Neven Mrgan and Gizmodo, Microsoft is “all in.” All in “the Cloud,” that is, though the poker metaphor of betting the company on an all-or-nothing strategy seems apt.

Reading some of Steve Ballmer’s vacuous corporate speak surrounding this campaign (including the following PowerPoint-ready bullet points), I am not overwhelmed with enthusiasm for the endeavor:

- The cloud creates opportunities and responsibilities
- The cloud learns and helps you learn, decide and take action
- The cloud enhances your social and professional interactions
- The cloud wants smarter devices
- The cloud drives server advances that drive the cloud

My perspective on this kind of “communication” (such as it is) has evolved over time. When I was 25, it intimidated me, because I didn’t understand it. When I was 30, it annoyed me, because I realized there was nothing to understand, and it was just wasting my time. Now, at 35, it worries me, because I realize that this is how the people who are running things — important things like Microsoft, for crying out loud — actually think. They write nonsense like this and think it’s meaningful.

I wouldn’t bet on that.

Update: In Ballmer’s defense, the full presentation provided a lot more details than this bullet list, but it’s still a lot of not really very much.

Twittegration (or… uh… something like that)

Yes, I should inaugurate this new feature with a profound, witty, or at least marginally purposeful post. Alas, I might as well just say “Hello world!”

This post is a test of a new Twitter integration I’m trying out, using the Twitter Tools plugin for WordPress. Here goes (hopefully not) nothing!

Update: Looks like it works. Now I just need to get my custom URL shortener integrated into it all.

Limitations inspire design

What makes great design? Why did design seem to take such a wrong turn in the ’80s and ’90s? What has prompted a partial resurgence of “great” design in recent years? And why am I asking all of these highly subjective questions?

My fascination with design first took hold in the early ’80s, and was largely attributable (along with my love of technology) to my experiences with the Atari 2600. I became obsessed with package design and logos, and I also became obsessed with the art of low-resolution, pixilated on-screen graphics.

My interest in “current” video games tapered off as the ’90s wore on, especially when the 3D polygon-based era began. All the new games just seemed ugly and stupid, even though, in an obvious way, they were more complex and more graphically detailed than the Atari games I loved as a child. Simultaneously, my fascination with logos and package design waned as both seemed to just get more obnoxious and overloaded with swooshes and swirls and gradients and shadows and beveled edges and all of the other excesses technological advances made possible.

I’ve wondered for a while what it was about blocky, bitmapped video game graphics that I found so aesthetically appealing. And, in much the same way, what it was about package design from the ’50s, ’60s and ’70s that just seemed so right to me, even though they were a lot simpler, and made using much cruder technology, than what was happening in the “now.”

Finally, I realized it was limitations that were the key to the great designs I admired so much. The designers were up against strict limits to what was possible. Mastering these earlier, more difficult techniques required years of practice and experience. And butting up against those limits to produce something of quality required real creativity. This realization led me to the axiom:

Great design happens when designers’ creativity exceeds the limitations of the technologies they use.

Once I understood this, suddenly it made sense to me why so many of the low-budget shareware games I’d seen for the Mac over the years looked and felt like crap to me, even though on a surface level they were clearly more advanced than those old Atari games: it’s easy to create a game on a modern computer, using modern graphics software and object-oriented programming languages. You don’t have to have any particular skill or knowledge to do so. But, because it’s so easy to do passably, it’s much harder to do really well.

Pitfall! and Super Mario 64: Yes, strangely, I really do prefer the one on the left.

Atari 2600 programmers needed an immense amount of knowledge of the intricacies of the system, and the tricks to exploit its extremely limited, but quirky, technical capabilities. You didn’t get into programming games for the Atari 2600 unless you knew what you were doing. Well, OK… there was plenty of shovelware in the system’s later years, but the ratio of good to crap was much higher among the 700 or so games released during that system’s lifetime than it is for the tens of thousands of mostly worthless games currently available for the iPhone.

So then, what is it that has caused — to some extent — “great” design to re-emerge in recent years, even as technology has advanced even faster than before? I suspect it’s due to a reawakening among designers to the merits of the earlier ways of doing things. Letterpress, for instance, has experienced a massive resurgence of popularity lately. “Retro” design is popping up everywhere. Perhaps it’s just that the hipsters are taking over the world, but I think this renewed awareness of what made mid-century design so great has led to designers re-imposing those limitations on themselves. Technology has advanced far enough now that there’s almost nothing that can’t be done, including recreating the limitations of earlier analog technologies in the digital realm. Think of things like Hipstamatic for the iPhone: it takes your iPhone’s digital photos and makes them look like something from an old point-and-shoot camera from the ’60s. Or look at the background design on Web Designer Wall, a visual style that saw a surge in popularity about a year ago but that’s inspired by watercolor and ink techniques that were especially popular in the ’60s. Or look at video games like The Legend of Zelda: Wind Waker (among others) that brought a cel-shaded animation style to 3D polygon-based video game design.

These are just a few examples off the top of my head of modern designers imposing limitations on themselves to inspire their designs, now that technology no longer forces those limits directly. If you can do anything, it’s hard to do anything well. It’s too easy to get lazy or to simply lack direction and focus. In the past, technological barriers forced designers to focus. Now, they have to do it for themselves. Fortunately, that’s starting to happen.

Group improvisation for one

In the mid-’90s, I was a member of a musical group called Bassius-O-Phelius. Working under a name based on an obscure Captain Beefheart reference, my friend Mark Bergen and I, occasionally supplemented by other musician friends, recorded a number of albums of free-form improvisation. Mark played organ, electric piano, and viola, and I played electric bass, woodwinds and percussion. It was all about experimentation and the power of music to convey mood and mystery. It was also kind of ridiculous, but we did everything with a sense of humor.

The Bassius-O-Phelius method was to use a 4-track cassette recorder, lay down an initial pair of tracks — typically on keyboard and bass — and then play the tape back and improvise another pair of tracks on viola, clarinet, and assorted other instruments. This led to some interesting results, as our improvisations were based not only on the live interplay of two musicians standing in a room together, but of those two musicians interacting with themselves via the prerecorded tracks.

For this year’s RPM Challenge, I decided to channel that spirit into a solo album, which I have entitled 222: Improvisations for 6 Instruments. Obviously the dynamic here is different: there’s only one of me, so I can’t interact with another player live. This difference was most apparent while laying down the first instrumental track: it was just me on the keyboard, with no frame of reference. My experience with Bassius-O-Phelius, however, taught me that it was important, among other things, to establish a steady, repetitious groove from time to time, anticipating opportunities for solos in subsequent tracks.

Another difference was the recording tools at my disposal: in the ’90s we recorded on a 4-track cassette recorder, but I recorded this album in GarageBand on my MacBook. The number of possible tracks is (in principle) unlimited, so I could easily lay down six individual instrument tracks without needing to worry about “bouncing down.” But there was another significant effect of using GarageBand: I could watch the waveforms of the other instruments as I played. Obviously this couldn’t totally allow me to “read the mind” of… well, myself… from the prior tracks, but it did allow me to anticipate major events. This might seem like “cheating,” but it actually felt more akin to the “two people in the same room” experience: while musicians are collectively improvising, it is common for them to make eye contact and give each other visual cues to facilitate group events in the performance.

Once the six instrument parts were recorded, I created 8 distinct “pieces” based on this single 8:38 track, by splitting up the instruments into different arrangements. For instance, the first track is just keyboard and guitar; the second is just Bebot and bass clarinet. Only on the final track do all six instruments finally come together and reveal the ultimate end product of my endeavors.

Incremental redesign

If you are the a regular reader of this blog, you may notice things look slightly different than they did before. The light blue striped background behind the right sidebar is gone; there’s navigation at the top; the left sidebar on the featured item on the home page has now become a standard element of all of the posts and, hey, the home page is now back to a standard one-post-after-another blog layout. Also, the sidebar widgets are different, and if you scroll waaaaaay down to the bottom, that’s different too. But since you’ve never bothered to do that before now, you probably wouldn’t have noticed anyway.

Incremental redesign seems to be more common with websites these days than the biannual complete overhaul we’ve grown accustomed to from sites large and small over the years. Why? Perhaps it’s a sign of maturity (of the designs, not the designers): designs stabilize over time as they’re refined based on user feedback. Perhaps it’s inertia: sites are so much more complex these days that, despite the benefits of semantic HTML and CSS, it can still be a massive undertaking to redesign a website from the ground up. And perhaps it’s strategic: designers have an idea where they’re going, but it can be jarring to users to have the proverbial rug pulled out from under them with abrupt and large-scale changes to a site’s design.

So, which is it in my case? Honestly, it’s probably a combination of all three. Anyway, I hope you like the refinements, and if not, feel free to let me have it in the comment section!

Nothing is real…

This fascinating video montage (apparently a promotional tool for Stargate Studios) shows just how much of what you see in outdoor scenes in movies and TV shows is really done with green screen. Surprising, amazing, and kind of disappointing. I’ll never believe anything I see on-screen again. (Not that I ever should have anyway.)

I think it would have been better with “Strawberry Fields Forever” as the soundtrack though, but I suppose they couldn’t get the rights. Maybe they should have used the “simulated live performances” from BlueBeat.com instead. (Source: LA Times)

Via kottke.org, via that’s how it happened.

My favorite Super Bowl commercial

Super Bowl commercials tend to scream at you, both literally and metaphorically. So a quiet, subtle commercial like the one Google aired is easy to miss. (The Focus on the Family commercial, for all the fervor preceding it, was also easy to miss.)

Luckily I didn’t miss the Google commercial. It was simple, and simply brilliant. Maybe it’s because I have a life-changing event in my own past that is at least partially traceable to a Google search, but I think the message here is powerful and moving: in the Internet age, profound events in your life can stem from things you find online. And what better way to find things online than Google?

My favorite moments are “What are truffles?” followed by “Who is Truffaut?” and when the user changes “Long distance relationship advice” to “Jobs in Paris.” It’s silly, I know, but I start to tear up at that one.

New room34/music site launched

My brief foray with Bandcamp is over, and a brand new room34/music site has officially launched!

This new version, I am proud to say, runs on cms34, a Content Management System I developed based on the CakePHP framework. I’ve been running numerous client sites on it for the past couple of years, along with my own Room 34 Creative Services site, but this is the first time I’ve really pushed its capabilities on a site of my own. The site has a few tricks up its sleeve (although most are in the admin interface right now), and more is on the way, including automatic transcoding of MP3s into Ogg Vorbis format for playback in the Firefox and Chrome web browsers.

Yadda yadda yadda. It’s not about the web geekitude (well, maybe for me it is)… it’s about the music. I’ve posted streaming and downloadable MP3s, cover art, background information, and CD purchase links for about a half dozen of my most recent projects, and over the coming weeks I’ll be filling in the rest of my “back catalog” going back to at least 2001, and perhaps even to my debut “album” from 1992, if I can round up the old cassette currently decaying in a box in the basement somewhere.

No one’s listening

Comments. Over the past decade, the Internet has become inundated with them. Ten years, ago, the concept of a “blog” was considered cutting edge, by those who even knew what they were. Now, they’re everywhere, and their general format — a dated archive of topical posts by one or a small number of authors, each of which is trailed by a string of reader comments — has become the standard structure for most news and information websites.

But… comments. Oh, comments. They help turn a one-sided online journal into a thriving community of engaged individuals. Or not. By now, the true nature of most comment threads — a bunch of morons yelling “FIRST” followed by a bunch of even bigger morons ranting at each other without ever engaging — is so well-known, so obvious, that it’s boring even to mention and somewhere between tiresome and excruciating to experience.

So, how long will it be before comments go the way of Internet Explorer 6 and Flash? (Oops… have I spoken too soon?) I think the day is coming soon.

Comment ça va?

Many prominent blogs, Daring Fireball for instance, have long eschewed comments (although the persistent commenters have found a way around that). Others are following suit. And now, it’s easier than ever for frustrated readers to take things into their own hands and silence comments wherever they go online.

I can’t tell you how tempting shutup.css is. I’ve spent more time angrily scrolling through insipid comment threads than I care to remember… but it’s driven me to rant before.

Jumpin’ Jack Flash

But, just like Flashblock (or, for you Safari users, ClickToFlash), I think if I were to try it, I would quickly go back, no matter how annoying the comments are.

Don’t get me wrong: I feel the same way about comments as I do about Flash. Both have potential, but far more often than not they are just intrusive and annoying rather than useful. I tried Flashblock for a few days last week, and I was happy not to be intruded upon with overlaid advertisements, intro animations, and other bandwidth- and time-wasting nonsense. But turning off Flash also meant I had to click an extra button to watch most videos, and even worse, to upload files on my WordPress blogs… not to mention the client sites I’m developing that have JWPlayer and YUI Uploader embedded in them. So, as much as I want to be rid of Flash, and as content as I am not to have it in iPhone OS, I decided I needed to turn it back on in Firefox on my MacBook.

The same goes for comments, but I don’t even need to try shutup.css to know I wouldn’t want to keep it. Sure, I hate the comments on most news and tech sites I read, but I like them on my own site, and I like them on the sites that I want to comment on.

Turn it on again

So, with both Flash and comments, there are proponents and opponents. It seems in the recent dust-up over Flash (or the lack thereof) on the iPhone and iPad, the most fervent supporters of Flash are Flash developers, or people who just hate Apple. And with comments, well, it’s pretty obvious: people who like comments (or, more specifically, like to make them) want them, and just about everyone else doesn’t. It’s clear to me that comments rarely add value, and they often detract from the sites they’re on. On the other hand, allowing comments on my sites has for the most part added value to them, and, critically, commenting on other sites has driven traffic to my sites.

Does this mean that the act of commenting is purely, or at least primarily, an act of shameless self-promotion? Perhaps. I wouldn’t post a comment if I didn’t think the comment had merit on its own, but I’ve also consciously posted comments on some sites knowing that doing so was a prime opportunity to bring some of those sites’ readers over to my sites.

And in the end…

By now it is becoming increasingly apparent to me that both Flash and comments are facing their demise. At least someone at Adobe gets it: Adobe is not in the Flash business, they’re in the “helping people communicate” business. Flash has been a tremendous tool for allowing people to communicate online for a long time where open standards have lagged behind. But by its nature, Flash is fundamentally opposed to what the web is really about. Nobody “owns” HTML or CSS or JavaScript. They’re open standards, and they’re the foundation of the web. Proprietary, closed technologies limit the web’s growth. Flash requires a plug-in (even if just about every computer comes with it preinstalled); Flash files are a “black box” to search engines and text-based systems; the technology resides in the hands of a single company whose fate will dictate the fate of all of the content locked into the format, and the fortunes of the creators of that content.

Comments, too, are about helping people communicate. But it’s become clear that — more or less, depending on the particular site — few people who engage in comments on a blog are really all that interested in communication. If comments cease to be seen as communication and instead become an ugly, depressing wasteland at the bottom of web pages, then they’ll die off too.

Looking forward into a new decade, I am beginning to see the old alignments of the Internet as we’ve known it falling away. There’s a convergence of new standards, new devices, and new means of communicating. And this naturally means that certain older ways, “standards” or not, will fade from our day-to-day experience. I’ll certainly be happier to see Flash go than comments, but then again, I think I’ll do just fine either way. Let me know what you think. Or not.