Displaying an Argument in a Drupal View’s Header
Let’s say you have a view in which you take in an argument you use for filtering content. That’s very easy, but what if you also want to display, say, “Most Recent {ARGUMENT}” before the list of content? It’s not as easy as it seems like it should be. It would be nice if there were a token-based solution, but the best way I can find is to use PHP in the view header.
You’ll need to enable the PHP Filter module, which is a core module that comes with Drupal.
I got this method from this comment, but I thought I’d repeat it here so that it will be easier to find for someone in the future. This takes the argument, turns the ‘-’s into spaces, and capitalizes every word. You may only want to do some of that, or something else, but it demonstrates how to get the argument to do with what you wish.
$view->args
is an array of the arguments in the request.
Here’s the code:
<h2>Recent
<strong>
<?php
$view = views_get_current_view();
print ucwords(str_replace('-', ' ',$view->args[0]));
?>
</strong>
</h2>
Do you know of a better way? Maybe one without having to use raw PHP in your view? That’s what the comments are for! (and thanks)
On Surprising Users
The Principle of Least Surprise is a common axiom in user interface design, and any sort of interface design (be it an object, a screen, or an API), and it’s a useful one. I (and everyone else) enjoy using an interface that just behaves exactly like I expect. It makes me comfortable, and gives me confidence that the product is well-engineered. It makes using a product *gasp* enjoyable.
But there’s another side to the double-edged surprise sword: delight.
Delight is when you surprise a user by transforming something they take for granted (something they normally wouldn’t give a second thought, if a first) and transforming it into something that directly and noticeably makes their experience better. Delight comes from making the user take that second glance and thinking, “Wow. They thought of everything.”
Delight makes people tell other people about your product.
Delight makes people want to use your product again and again.
Delight makes your product stand out from your competitors.
Delight makes ordinary extraordinary.
Delight people.
Have thoughts? Leave a comment.
It’s the Misadventures
My story about misadventures and getting to Vail is live on DCSki.
It’s a humorous narrative as opposed to a dry (though still fascinating, of course) report, and features a possessed GPS unit, car crashes, a make believe conversation I had with myself, and – best of all – me!
I had a lot of fun writing it, and I think it’s a pretty fun read. You can check it out on the front page at time of writing, or at its permanent home.
Here’s the teaser:
Ah, Vail. The beauty, the splendor, the adventure. The snow is whiter, the sky is bluer, the mountains are bigger and the people are prettier. Numerous Firsthand Reports on DCSki have covered these aspects of Vail. But DCSki Columnist J.R. Patten veers off the beaten path to provide an unconventional look at Vail — or, more to the point, the misadventures of getting to Vail.
I hope you laugh, cry, and feel the irresistable urge to send me tons of money.
Feel free to leave comments on DCSki or here, whichever tickles your fancy. I think I’ll write a commentary about it soon, maybe. I’d like to, but it all depends on if the muse strikes (ie. smacks me in the forehead).
My Report on The Canyons is Live
You can check it out on the front page of DCSki (at time of writing) or, at its permanent home.
Thanks for reading!
Now I’ve got to write one on Vail.
Things I Hate: Video That Auto-plays
Here’s the start of a new series with an incredibly unique and totally innovative theme: Things I Hate. Anyone want to guess what it’s going to be about?
That’s right, things I hate. You’re a genius. It’ll be a nice place to let loose my bitter side…
Anyway, the first thing:
Sites that have video that starts playing automatically
Say What?
Remember back in the good ol’ days of “Web0.5″ (there will soon be a similar article on web “versioning”)? People used to have songs and sounds that played in the background when their pages loaded. I’m sure there are still some horrifying sites out there that still do it. (*cough* MySpace *cough*)
Playing video (and anything else that makes noise) on page load is the same thing. I despise it, and chances are if you do it, I’ll instantly close your page and never come back (not on purpose, anyway).
Why I Hate It
Let’s examine why auto-playing stuff in the background is moronic:
- Your page is probably open in the background – do you really think you’re the only page I’m viewing right now? Does your page really deserve to command my attention over the other pages I actually wanted to be paying attention to? Umm… NO. I opened it in the background for a reason. I wanted to read it on my own time… until I realized it played something when the page loaded. Now I’ll just close it and never go back.
- I probably have music playing – There’s this crazy new-fangled thing people do: it’s called playing music on their computer while they’re doing other things. Absurd, I know. But do you really think I want my favorite song interrupted by your stupid video? Umm… NO. If I want to see your newest uploaded video, I’ll click play myself, on my time. Which brings me to my next point…
- You’re not letting me choose how to view your site - This point is a bit of a catch-all. I want to view your site the way I want to view it. Don’t force me to view it your way. Your design should be good enough to suggest to me how I should view it, and to lead me to the most important things. You shouldn’t need to be so pushy as to leave me no choice but to view your stinking video.
Chances are, you want me to like your site (point 1). You probably want me to stay around a while (point 2) too. Guess what auto-playing crap on your front page does? No, really, hypothesize away. I’ll wait. Actually I won’t. Yay for asynchronous communication.
I’ll bet if you’re one of the people who needs to be reading this article, you guessed wrong, because you didn’t immediately remove the auto-playing video from your front page. So let me enlighten you…
It makes the first thought I have about your site a bad one (see point 1), and it makes me close the stinking tab (see point 2) because I don’t feel like finding the pause button, and I’ve realized that the rest of your site is probably just as bad or worse as the front page and is therefore not worth my time.
Here’s the fundamental issue (that’s why I’m making it bigger):
Asking the user to click play is not asking too much. If they want to see your video, they’ll click play. If they don’t, then you probably have much bigger problems, but certainly shouldn’t be forcing them to watch it!
So congratulations. By auto-playing crap on your front page, you have done the opposite of what you meant to and what you need to do to have a successful site. And in the process, you’ve achieved a near-perfect level of FAIL. You should celebrate.
Now go fix your page.
Anyone else hate this as much as I do, or brave enough to admit you think it’s a good idea? Leave a comment. That’s what they’re there for!
Make Google Analytics Default to Today
I love Google Analytics. It’s phenomenal. It really helps me track how a site is doing and optimize the visitor experience. However, there’s one thing about it that bugs me to no end. It defaults to showing you the last full day’s statistics.
Well, I’m a statistics junkie, so that doesn’t make me happy. I want to see how I’m doing today, as close to real-time as I can. As far as I can tell there is no setting you can set to make it default to view today by default. The only way to do that without manually changing the dates is to set the pdr variable in the URL.
So, here’s how to create a bookmark that will take you to today’s statistics (these instructions are for Firefox, but I imagine Safari and IE can’t be too different).
- Drag this link to your bookmarks toolbar: Today’s Analytics
- Find out your Analytics ID: You can do this by visiting your dashboard and looking for the id parameter in the URL.
- Replace XXX in the bookmark with your ID: Right click on the bookmark you created, and go to Properties. Scroll toward the end of the URL, and find “XXX”. Replace this with the ID you found.
- Click the bookmark
You should now be able to use that bookmark to view your Google Analytics with a default end date of today.
If you don’t like any of the other settings, you can change around the URL at the end to suit how you like to do things.
Now you don’t have to always change the date as soon as you log in. Enjoy!
Well, WordPress seems to have messed up the link. I’ll fix it as soon as I can…
Questions, comments? I’d love to hear from you. Just leave a comment down below!
Yet Another Reason Depending On Oil is Utterly Moronic.
First off, just go take a little peek at this graph. I’ll wait.
Yep. That’s right. Gas prices now, even adjusted for inflation, are worse than the oil crisis of the 1970′s. Gasoline prices are getting absurd, and there’s nothing we can do about it. Why’s that? Because we rely on a veritable Gasoline Mafia. OPEC is a mob, a cartel. They use thug tactics to manipulate us like little marionette puppets.
And we keep giving them more and more power!
Think I’m exaggerating? Check out this report that came out today.
OPEC has our arm behind our back and is twisting until we say “uncle”, and we are allowing them to manipulate us because of our foolish dependence on oil.
Fighting them is not the answer. We need to make them irrelevant. It’s our own fault for being so all-out dependent on oil. Even if they liked us, it’s just plain near-sighted and irresponsible to depend so heavily on a non-renewable resource.
And they don’t like us.
I fear that oil prices are going to be a very major issue in the upcoming election, but not in a good way. Both sides will be trying to buy votes by promising to lower gas prices, because that’s what people want to hear.
But the issue shouldn’t be lowering gas prices. Find me a candidate who is dedicated to the vision that, come the next election, gas prices won’t matter at all because gasoline usage is on its way out the door, and I’ll show you the guy I’m voting for, regardless of party.
It’s not about making oil cost less! It’s about realizing that we shouldn’t be using it. We have grand visions for the future (well, I do anyway) but we will never realize any of them while we are still relying on gasoline as our major source of power.
There are many reasons using gasoline is such a terrible idea, but today’s article about OPEC just brought this particular one to the front of my mind. So, in sum: It’s an amazingly stupid idea to put so much power in the hands of people who don’t like us. We are letting OPEC push us around, or at the very least have given them a good reason to think they can, and that will only end badly for us.
The Awesomeness that is Rhythmbox
There’s something to be said for a piece of software that does exactly what you want it to do, behaves exactly how you expect it to, stays out of your way until you need it, and makes you happy. That’s exactly why Rhythmbox is so darn great. But let’s back up a little bit… Rhythmbox is a Music Player / Library Organizer for Gnome. It’s comparable to, though quite different than, Amarok for KDE. I used to use KDE and was madly in love with Amarok. It was and still is a phenomenal piece of software, but I think Rhythmbox has stolen its place in my heart. Amarok has some features I’d love to see in Rhythmbox, and it has a much stronger community, but
Rythmbox does what I want it to, the way I expect it to, without getting in my way
and that’s why I love it so much.
For instance, when I’m browsing music, the next song played comes from the list I’m viewing just like you’d think it would. Rating songs is one-click simple, but out of the way. The play queue lets me queue up songs (imagine that) that I want to hear, but don’t want to interrupt the currently playing song for. Oh, and it minimizes to the tray (if you want) for the ultimate out-of-the-wayness.
None of these things are unique or particularly innovative, but what makes this software so wonderful is that it does just what it should, how it should. You might say that it follows the Principle of Least Suprise. It doesn’t try to be something it’s not, but it is a fully-capable, powerful music player. It’s built on a plugin architecture and has an integrated Python console, so if you want more raw power, you can get it.
It does what I want, the way I expect, doesn’t clutter my interface, and lets me harness its full power easily if I want. I think that’s a goal all software should aspire to.
So here’s to you, Mr. Heretofore Unglorified Music Player. You don’t get a lot of attention. You’ll never get downloaded 8 million times in one day, but I wish the rest of my software would be more like you.
Don’t Look at the Rock!
… because if you look at the rock, you’ll run right into it. I promise. Let me explain…
The Story
I recently took a 5-week whitewater kayaking course. Kayaking is a blast. It can be very dangerous (despite what Into the Wild might have you think), but it’s complete and total fun and exhilaration once you get the hang of it. Nothing beats spending a day on a wild and scenic river. You’re peaceful, relaxed, and quiet one minute and the next minute, adrenaline is screaming through your veins while you’re screaming through a rapid. On the first few trips, though, we (the students) kept running into everything. That’s to be expected when you don’t even really know how to paddle straight in moving water, but even once we got the hang of that we still kept running into stuff.
The instructor would tell us, “There’s a big rock on river right. Be sure to squeeze left of it, or you’ll get stuck.” So we’d start paddling down the rapid, spot the big rock they told us about and try our best to squeeze to the left of it. Then we’d run smack into it. Almost every time. No matter how hard we tried to avoid things, we kept running into them. Then they told us a secret, and after that I didn’t run into the big rocks anymore (that’s not to say I didn’t flip or take terrible lines down the rapids. I did. But I didn’t run into anything they told us to look out for).
The secret didn’t involve any paddling trick, some weight-shifting maneuver, or how to lean the right way (all of which are actually important). The trick they told us was this:
Quit looking at the rock. If you look at the rock, you’ll hit it. Know the rock is there, but instead of looking at it, look where it is you want to go instead. If you look where you want to go, you’ll go there, and you won’t hit the rock.
They were right. We were concentrating so hard on the rock that we unconsciously steered the boat right for it. The harder we tried to avoid the rock, the more likely we were to run into it. Once I stopped looking at the rock and focused my attention on where I wanted to go, my skill improved dramatically, and I had a lot more fun. And I stopped running into the stuff they told us to look out for. Finally I was going where I was trying to go instead of getting stuck on obstacles.
The Moral
I think the parallels to life are pretty obvious. When you’re working at something — be it a business, school, a hobby, or a personal goal — there will be big rocks that you’ll have to avoid. The key is to not look at them, not dwell on them. If you spend your time thinking about them, you’ll run right into them. Instead, just know they’re there. You don’t want to be oblivious to them, but don’t dwell on them.
Focus your attention on where you want to go, and you’ll stop running into the obstacles and start moving in the right direction. You’ll get a lot better at whatever it is you’re doing, and you’ll have a heck of a lot more fun, too. I guarantee it.
Got a good story about running into stuff (metaphorically or not)? Like to kayak? Have other advice? I’d love to hear about it! Just leave a comment below.
