Teaser Images For Thesis Theme

by James on March 3, 2011

I absolutely love the Thesis Theme framework for WordPress. Sure there’s lots of really good frameworks out there now but Thesis, in my opinion, is one of the best. However, there’s one drawback and that’s being able to dynamically add a thumbnail to a teaser post. Most themes, as well as, frameworks insist on having you add a link to a thumbnail in one of the post meta fields. This is fine, it’s also foolproof , for the most part but it’s also a step that’s annoying as all heck to me.

If you search the web there’s lots of creative solutions out there, but none really did what I wanted. Below is a sample of how I wanted to layout the main page on my site Reality Wired.

Most of the time posts have an image and with the new the_post_thumbnail function in WordPress 3.x it’s fairly easy to get this. But what if your post doesn’t contain an image? Maybe it contains a Youtube video or a Flickr image what then? Well I came up with what I think is a fairly creative solution. Here’s the code.

/* Thumbs for teasers */
function thesis_teaser_wp_thumb() {
	global $post, $posts;

	unset ($attachments);
	unset ($video_id);
	$default_thumb =  '<img width="100" height="100" src="'.THESIS_CUSTOM_FOLDER.'/images/noimage.gif">'; 

	$args = array( 'post_type' => 'attachment', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID );
	$attachments = get_posts($args);

	// Check for a you tube video in the post and grab the video id
	preg_match('#http://[a-z]*?[\.]?youtube\.[a-z]*?/v/([\w-]*)#i', $post->post_content, $matches);
	if (!empty($matches[1])) { $video_id = $matches[1]; }

    if ( has_post_thumbnail() ) {
    	the_post_thumbnail('thumbnail');
    }
    elseif (!has_post_thumbnail() && isset($video_id)) {
	if(@fopen("http://img.youtube.com/vi/$video_id/default.jpg",true)) {
		echo '<img width="100" height="100" src="http://img.youtube.com/vi/'.$video_id.'/default.jpg">';
	} else {
		echo $default_thumb;
	}

    }
    elseif (!has_post_thumbnail() && !empty($attachments)) {
	foreach ( $attachments as $attachment ) { the_attachment_link( $attachment->ID , false ); }
    }
    else {
	echo $default_thumb;
	}
}  

To use this function in Thesis you need to first add it to your custom_functions.php file inside your thesis_18/custom directory. Next you call this function via a hook. In the case of my blog I used the thesis_hook_before_teaser_headline hook location. Add this next line somewhere in the same custom_functions.php file. (I like to keep all my hooks at the top of the file but it can really go anywhere. Some prefer to place near the function itself, it doesn’t matter.)

add_action('thesis_hook_before_teaser_headline', 'thesis_teaser_wp_thumb', '1');  

Essentially we are telling WordPress that the hook should execute right before the teaser headline is processed and the third parameter, a 1 in this case, also tells WordPress to execute this function before any other hooks in this location.

Finally I’m adding a bit of css to my custom.css file (also located in the thesis_18/custom folder).

.custom .teaser {
border-top:2px dotted #BBBBBB;
margin-top:2em;
padding-top:2em;
text-align:justify;
width:100%;
}
.custom .teasers_box {
border-top:0 none;
padding-bottom:0;
padding-top:0;
} 

.teaser img {float:left; padding-right:10px;}
a.teaser_link {float:right;clear:both;}
.format_teaser p {display:table;}
.teaser .format_teaser { margin-top:.5em; margin-bottom:.5em; }
.teaser .teaser_comments { float:right;}

Once you have this code in place it should alter your Thesis teasers to look like the sample I posted above. If you don’t like the layout just skip the css styling or customize your own. The guts you care about is the thesis_teaser_wp_thumb function. As is, the function should handle embedded Youtube videos (assuming you’re using regular embed code). So what if you want to use a different service? Well, I typically just use Youtube and it’s rather easy to get the thumbnail that Youtube generates when it encodes a video. That said, you should be able to modify this code to work with your chosen service.

// Check for a you tube video in the post and grab the video id
preg_match('#http://[a-z]*?[\.]?youtube\.[a-z]*?/v/([\w-]*)#i', $post->post_content, $matches);
if (!empty($matches[1])) { $video_id = $matches[1]; }

We use a preg_match to strip out the Youtube video id which we then insert into the code snippet below to call the thumbnail.

if(@fopen("http://img.youtube.com/vi/$video_id/default.jpg",true)) {
echo '<img src="http://img.youtube.com/vi/'.$video_id.'/default.jpg" alt="" width="100" height="100" />';
} else {
echo $default_thumb;
}

Here I check to see if the thumbnail I’m after exists and if it does I build the image code. If it doesn’t then my default thumbnail gets displayed.

I use the same process to grab thumbnails from Flickr and that code could be modified to fit other sources. At some point I turn this into a plugin but for now I thought I would share what I have. Feel free to use it, critique it or whatever.

Life Lessons from 40 Films in 7 Minutes

by James on March 1, 2011


Haven’t posted in a bit but I happened to run across this video today and had to share. If you love movies then you’re going to like this. The video contains wisdom from 40 films, most of which you’ll probably recognize. For Star Wars fans, there’s plenty of Star Wars clips, all the great ones plus a few more. Anyway, check it out, it might just cheer you up.

Growing up without a cell phone

by James on February 8, 2011


If you are 36, or older, you might think this is hilarious! When I was a kid, adults used to bore me to tears with their tedious diatribes about how hard things were when they were growing up; what with walking twenty-five miles to school every morning….Uphill… Barefoot…BOTH ways…yadda, yadda, yadda. I remember promising myself that when I grew up, there was no way in hell I was going to lay a bunch of crap like that on my kids about how hard I had it and how easy they’ve got it!

Well now that I’m over the ripe old age of forty and about to become the parent of a bonafide teenager, I can’t help but look around and notice the youth of today. You’ve got it so easy! I mean, compared to my childhood, you live in a freaking Utopia! I hate to say it, but kids today, you don’t know how good you’ve got it!

I mean, when I was a kid we didn’t have the Internet. If we wanted to know something, we had to go to the damn library and look it up ourselves, in the card catalog!!

There was no email!! We had to actually write somebody a letter – with a pen! Then you had to walk all the way across the street and put it in the mailbox, and it would take like a week to get there! Stamps were 10 cents!

Child Protective Services didn’t care if our parents beat us. As a matter of fact, the parents of all my friends also had permission to kick our ass! Nowhere was safe!

There were no MP3′s, Napsters, iTunes or torrents! If you wanted to steal music, you had to hitchhike to the record store and shoplift it yourself!

Or you had to wait around all day to tape it off the radio, and the DJ would usually talk over the beginning and @#*% it all up! There were no CD players! We had tape decks in our car. We’d play our favorite tape and “ejected” it when finished, and then the tape would come undone rendering it useless. Cause, hey, that’s how we rolled, Baby! Dig?

We didn’t have fancy crap like Call Waiting either! If you were on the phone and somebody else called, they got a busy signal, that’s it and then our parents would ground us from the phone, for like forever.

There weren’t any freaking cell phones either. If you left the house, you just didn’t make a damn call or receive one. You actually had to be out of touch with your “friends”. OH MY GOSH !!! Think of the horror… not being in touch with someone 24/7!!! And then there’s TEXTING. Yeah, right. Please! You kids have no idea how annoying you are.

We didn’t have fancy Caller ID either! When the phone rang, you had no idea who it was! It could be your school, your parents, your boss, your bookie, your drug dealer, the collection agent… you just didn’t know!!! You had to pick it up and take your chances, mister!

We didn’t have any fancy PlayStation or XBOX video games with high-resolution 3-D graphics! We had the Atari 2600 with games like ‘Space Invaders’ and ‘Asteroids’. Your screen guy was a little square! You actually had to use your imagination!!! And there were no multiple levels or screens, it was just one screen.. Forever! And you could never win. The game just kept getting harder and harder and faster and faster until you died! Just like LIFE!

You had to use a little book called a TV Guide to find out what was on! You were screwed when it came to channel surfing! You had to get off your ass and walk over to the TV to change the channel!!! NO REMOTES!!! Oh, no, what’s the world coming to?!?!

There was no Cartoon Network either! You could only get cartoons on Saturday Morning. Do you hear what I’m saying? We had to wait ALL WEEK for cartoons, you spoiled little rat-bastards!

We didn’t have microwaves. If we wanted to heat something up, we had to use the stove! Imagine that!

Our parents told us to stay outside and play… all day long. Oh, no, no electronics to soothe and comfort. And if you came back inside.. you were doing chores!

And car seats – oh, please! Mom threw you in the back seat and you hung on. If you were lucky, you got the “safety arm” across the chest at the last moment if she had to stop suddenly, and if your head hit the dashboard, well that was your fault for calling “shot gun” in the first place!

See! That’s exactly what I’m talking about! You kids today have got it too easy. You’re spoiled rotten! You guys wouldn’t have lasted five minutes back in 1970 or any time before!

Regards,
The Over 40 Crowd

My Favorite Super Bowl Ad

by James on February 7, 2011


There were a couple of other ads the were notable but for the most part this years Super Bowl ads were rather boring I thought. Mostly just knock offs from previous years with very little originality. I guess at $3M for a 30 second ad spot, that doesn’t leave much in the way of a development budget. The automakers however put the bail out money to good use, it seemed there was an automotive commercial ever break. My hands down favorite though was the Volkswagon commercial featuring Darth Vader and using the force. You just can’t go wrong with Vader in a commercial.

What was your favorite Super Bowl ad?


Apparently the cellphone companies are all in cahoots with scammers to rip off their customers and the FCC is powerless to do anything about it. That’s right and it’s all nice and legal like. Have you ever gotten those unwanted text messages from some company offering you some service you don’t need or want? Yeah, we all have. Have you paid much attention to them or just ignored them like most telemarketing calls? I pretty much ignore them.

So here’s the scam. Whenever you get one of these text messages from some company like Flycell, offer anything from ringtone downloads to celebrity gossip or some other nonsense, if you’re like me you just ignore it. I mean logically, if it’s offering something and you don’t want it, ignoring it should be the same as saying “no I don’t want it” right? WRONG!!!! Somewhere in the message is usually a statement that says something to the effect “please reply if you DON’T want this service”. By ignoring the message, the company is assuming you DO want whatever it is they are promoting and charge it to your cellphone account. Which AT&T and most other service providers seem to allow with out any further confirmation.

Right now you’re going WTH!!! right? I know. After calling AT&T they removed the charges but said it wasn’t their system, it was the customers problem because that person (ie: me) didn’t respond to the text message. Is it just me or does that just seem bass ackwards? It means any Joe blow scammer can sign you up to any service via a mobile subscription and you’d never know it until the bill arrived. What a crock. They did say they could put a mobile purchase block on the line but that would also block purchases made from iTunes or the Apple App store which isn’t very reasonable if you’re an iPhone user.

This same type of thing happens on Facebook as well. Those wacky surveys that your friends are “supposedly” taking? Well pay attention to those if you’re playing around. NEVER give one of them your cellphone number or else. In many cases they ask for a cell number at the end of the survey which in most cases automatically subscribes you to some service.

……… and still wonder why I miss my StarTac from circa 1999 so much.

Walt Disney World 2011: Animal Kingdom

by James on January 31, 2011


Sunday was our first full day at Disney World so we decided to do Animal Kingdom first. We rode the shuttle which let us off near the gate, much like at Epcot the evening before the first thing we noticed was the lack of people as compared to our last visit. Animal Kindgom is a great park but hard to compare because it’s mostly just a zoo with a healthy dose of Disney Magic thrown in. The three biggest attractions in the park are the Kilimanjaro Safaris, Expedition Everest and the Nemo Musical.


We skipped the dinosaur dig this time and went straight for the Kilimanjaro Safaris. It’s a cool ride, the upside being you get to sit and ride through the animal areas, the downside is it’s very bumpy and fast, making it really hard to take pictures.

Expedition Everest is a roller coaster, it’s very similar to the Big Thunder Mountain type roller coasters found at various parks. The twist here is at one point you run out of track, where the Yeti has torn them up, then you go backwards for a bit, then through the Yeti caves where you encounter the legendary creature, narrowly escaping it’s clutches. It’s a pretty cool coaster, the downside being since it’s the only coaster at the park it’s also busy, all the time.

The Nemo musical is an awesome show, it’s a live action show that tells the story of the young clown fish using stunning costumes and cirque du soleil style acrobatics. It really is an awesome show if you get a chance to see it.

We did a few other rides at the park but spent the most time walking through the The Oasis Exhibits and Pangani Forest Exploration Trail, both areas we got crushed through last time we were there. Again, being it’s mainly a zoo, there’s lots of stuff to see that’s well blended with the surroundings. The one thing we missed was the Maharajah Jungle Trek which had just opened the day we were there and some how we missed the entrance for it. Oh well, it’s on the list for next time.

Animal Kingdom closes at 5:00pm in the winter making for a short day. They said they do this because all of the animals on the range are trained to respond to a certain sound that tells them it’s time to come in for the evening and it took about 2 hours to get all the animals in their pens for the night. I’m not sure if you can take a behind-the-scenes type tour but that would be really cool to learn more about how they train the animals and stuff.

So, after a great first day we headed back to the resort, opting to go for a light day instead of heading to another park. Turned out to be a good thing too, we were able to do a bit of shopping at the Super Target, grabbed some ponchos because they were calling for some rain on Monday.

Walt Disney World 2011 ( Part 1 )

by James on January 27, 2011


After staying the night in Brunswick, Ga we got up and had a leisurely breakfast before making the final 3.5 hour trip into Orlando. We couldn’t check in at the resort until 2pm so we were in no big hurry and we arrived around 2:30pm. We stayed at Wyndham Bonnet Creek Resort two years ago and found it very convenient so we chose to stay there again, not to mention that being able to use our time share to cover both families traveling was extra incentive. It’s only a 9.5 drive (according to Google and the GPS) but last time it took 14 hours and we didn’t figure any of the boy nor Addison in particular would tolerate that much time in the car so we chose to split the trip going down into two legs. Man what a great idea that was and rolling past the Disney entrance sign around midday was awesome.

After checking in we decided to check out the rooms before dragging luggage out of the car. Normally, if you’d already stayed at a resort you might not do this, but for this trip we had a ton of available points to burn so I booked two Presidential Suites which were supposed to be a step up from the very nice suites we had two years ago.

Supposed to be a step up doesn’t do the rooms justice in this case, it was more like two or three steps up. The regular suites are nice but the Presidential Suites are REALLY NICE!!! [click to continue…]

Disable WordPress Autosave

by James on January 25, 2011

For some time now WordPress has had this rather annoying feature called Autosave that will save copies of each edit made to a post or page at some predetermined interval. I say annoying because I don’t use it and there are numerous plugins and posts dedicated to turning this feature off. None of which seem very effective. I suppose, if you’re some kind of hardcore editor the autosave function can be a life saver, or if you tend to write 1000 word posts then having an autosave function might be worth your while, but overall it just gets annoying, not to mention how badly it clutters up your database.

For whatever reason, the WordPress 3.x series still doesn’t feature an option to turn this off via wp-admin. Not sure why. At any rate, there is a very easy way to turn the autosave feature off. All you have to do is add the following line to your wp-config.php file.

define('WP_POST_REVISIONS', false );

Add it to the bottom of your config file and save. Simple as that.

Oh and if you don’t completely want to turn it off you can also specify how many times it saves. Simply add to your wp-config.php file:

define('WP_POST_REVISIONS', 3);

where the number 3 is the amount of times you wish autosave to save your post.

A few people using this plugin have reported that it doesn’t work with BuddyPress. After some investigation it appears to be because BuddyPress has it’s own registration template and doesn’t use some of the standard hooks WPMU uses during the initial signup process.

Not a big deal however in order to make this plugin work with the default BuddyPress theme you will have to make 1 manual edit to a theme file. I couldn’t find any better way to get the necessary check into their workflow but it’s a pretty simple edit.

Jump to the main plugin page WPMU Block Spam By Math, use the download link to get the updated plugin (version 1.1) and scroll down to the instructions and follow the note for BuddyPress users.

Post any issues in the main plugin post.