cc licensed ( BY NC ) flickr photo shared by t3hWIT


Don’t know where to put a comment on a #ds106 student blog as part of the Magnificent Seven Blog Comment Challenge?

I have the link for you.

With some rubbing together of magic dust and a dab of elbow grease, I have a new feature for the various “sections” of ds106- these are classes we know of who’s student blogs we are syndicating into ds106; all of these posts that come in carry an extra tag we can use to slice, dice, and make fries out of.

After a few variatoions of setting up a random picker in the Assignments Collection, I saw it would be easy to do something for the posts we bring in. The exception here is that we want recent stuff, so these scripts only look for posts published to ds106 n the last 3 weeks.

Without further ado, give thse a spin:

And the links are available on the specific section pages on the main ds106 site.

This is achieved with a little php magic. The first thing I had to do is to add a few bits to by functions.php template to add some key functionality.

First we have to set up our code so we can pass an extra parameter in our URLs, the one that identifies that “tag” we use internally to identify each section.

Next, and this took a little digging on the codex , when we do the work of finding our random posts, to keep it to ones in the last 21 days, we have to add another block of code to functions.php. This essentially adds a bit of mySQL logic needed to do a date offset (note he example in the codex is 30 days, I shrunk it a week)

Now what we have to do is to create a dummy wordpress page. The content it has can be BLAH BOOOGER BOP since it will not be used, the page is a holder we will populate dynamically via its template Heck it can have typos.. But what I want its to make sure it’s ‘slug” is named ‘random’;

Now we create a new template named page-random.php – it is invoked only if a wordpress page n my site has a slug named… random!

What we are doing is first finding out if the URL has a parameter like “tag=purpledinosaur”. We set up our new function so we can filter the query results we will do by the date function set up (published in the last 21 days). Following this, we make an array for some parameters to pass to a wordpress function that looks stuff up in the database. We want it to looks for things that are published posts (no pages, no drafts); we only want one, and the ‘orderby” is the magic paramater, it says to brings us a random result.

If we did get a paramteer passed to us, we will add ne more thing to look for, published posts tagged “purpledinosaur”

We runt he query, do some cleanup, and that grab the one result- from that post data we can get its URL (get_permalink()) and just send the viewer there via the wp_redirect() function.

It all works pretty damned smoothly. The one thing I am stuck on is I thought I could make a case for when no parameters are passed, that I could just pick a random one from all syndicated posts. I tried some extra query parameters based on the post meta data,. but all I ever get is the most recent post.

I love going random!

And thus, you have no excuse not to have fun giving s blog comment to our students.


click (and comment).

How fun is THAT?

cc licensed ( BY NC SD ) flickr photo shared by Maggi_94

Profile Picture for Alan Levine aka CogDog
An early 90s builder of the web and blogging Alan Levine barks at on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person.


  1. I left a couple of comments and it was easy! I loved the idea of random. Sometimes when I’m asked to comment on a class, there are so many students and I feel like I have to comment on them all or hurt someone’s feelings. That pressure sometimes turns me away from leaving any comments. This was quick and easy! Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *