Andy Warburton

Sleep Deprived Geek in Blunderland

Add CSS Class to WordPress Body Tag If Active Sidebar Present —

I recently started work on a theme that I wanted to make truly flexible. As part of this I wanted to add a CSS class to the <body> tag of ‘has_sidebar’ in the condition that the site had a sidebar with widgets present (an active sidebar).

I found a few tutorials but they were for old versions of WordPress and didn’t work in the current (3+ versions of WordPress). After a bit of hacking about I managed to get the following code working.

To use, simply add this to your Themes functions.php file:

function has_sidebar($classes) {
  // add 'class-name' to the $classes array
  $classes[] = 'has_sidebar';
  // return the $classes array
  return $classes;
}

if (is_active_sidebar('right_sidebar')) {
  add_filter('body_class','has_sidebar');
}

Following some discussion with some WordPress experts, I now present to you, a new improved version of the above code that moves the conditional inside the function rather than flapping about on its own.

function has_sidebar($classes) {
    if (is_active_sidebar('sidebar')) {
        // add 'class-name' to the $classes array
        $classes[] = 'has_sidebar';
    }
    // return the $classes array
    return $classes;
}
add_filter('body_class','has_sidebar');

It’s also recommended that if you use this code in your own theme that you prefix the function name with the name of your theme (replace all occurrences of ‘has_sidebar’ with ‘yourtheme_has_sidebar’. This just prevents clashes with any other functions contained within plugins.

The updated code has now been merged into all of my currently available themes: Terminally, Hello Sexy and Fiver.


Game Month is here! —

Well… who’d have thought it. In a couple of weeks, I’ll be celebrating 30 years on this planet. I feel like I’m doing pretty well all things considered and I’ve had a much easier life than many people on this planet so despite my birthday approaching rapidly I don’t have much to feel blue about (although I do feel a mid-life crisis may be in order in coming months #firstworldproblems).

wallpaper_assassins_creed_07_1600

The good news is, November is the month all the awesome games start coming out. I don’t get to play games much since the arrival of my little sprog, however I’m putting some time aside after my birthday for some fun and games. I’m a huge fan of The Assassins Creed and Saints Row series of games, and they both have sequels coming out on the 15th November (Assassins Creed Revelations and Saints Row the Third). I’m also likely to grab the new Batman game – Arkham City as I love anything that’s open world and sandboxy, especially when it involves super heros!

I’ll be celebrating with a birthday buffet at an all-you-can-eat Chinese restaurant in my home town of Stafford with my son and family around, then home and a week off work during which time I’ll be trying to fit in three large sand-box games! Should be fun!

I’m not a huge social butterfly, but if you know me in reality and want to come along, consider this an invite – drop me a tweet or an email and I’ll give you the date/time and place.


Make room for beer —

my wife just emailed me this lovely tale… Enjoy!

When things in your life seem almost too much to handle, when 24 hours in a day are not enough, remember the mayonnaise jar and the 2 Beers

A professor stood before his philosophy class and had some items in front of him. When the class began, he wordlessly picked up a very large and empty mayonnaise jar and proceeded to fill it with golf balls. He then asked the students if the jar was full. They agreed that it was.
The professor then picked up a box of pebbles and poured them into the jar He shook the jar lightly. The pebbles rolled into the open areas between the golf balls. He then asked the students again if the jar was full. They agreed it was.

The professor next picked up a box of sand and poured it into the jar. Of course, the sand filled up everything else. He asked once more if the jar was full. The students responded with a unanimous ‘yes.’

The professor then produced two Beers from under the table and poured the entire contents into the jar effectively filling the empty space between the sand. The students laughed.

‘Now,’ said the professor as the laughter subsided, ‘I want you to recognize that this jar represents your life. The golf balls are the important things—your family, your children, your health, your friends and your favourite passions—and if everything else was lost and only they remained, your life would still be full.

The pebbles are the other things that matter like your job, your house and your car.
The sand is everything else–the small stuff.

‘If you put the sand into the jar first,’ he continued, ‘there is no room for the pebbles or the golf balls. The same goes for life. If you spend all your time and energy on the small stuff you will never have room for the things that are important to you.

‘Pay attention to the things that are critical to your happiness. Spend time with your children. Spend time with your parents. Visit with grandparents. Take time to get medical checkups. Take your spouse out to dinner. Play another 18. There will always be time to clean the house and fix the disposal. Take care of the golf ball first—the things that really matter. Set your priorities. The rest is just sand.’

One of the students raised her hand and inquired what the Beer represented. The professor smiled and said, ‘I’m glad you asked.’ The Beer just shows you that no matter how full your life may seem, there’s always room for a couple of Beers with a friend.’


One more thing… —

One more thing I forgot during last weeks little rant on the lesser known peculiarities of being a parent… DANGER! Kids are dangerous. Today my son has head-butted my wife three times, tried to jam a whole stick of Celery down my throat and woken me up by stamping on my man-danglies. I shit you not.

That’s just today. The little thug has already broken two pairs of glasses this year and this morning pulled a mug out of a cupboard and hurled it across the kitchen. Babies should come with riot equipment as standard cos you can guarantee that you’ll be hurtin’ once they gain the ability to move around freely.


Stupid Looters —

Over night some images appeared on Twitter showing supposed evidence of people having stolen iPads and iPhones from major outlets during the London/Birmingham/Manchester riots (not Apple stores as far as I can tell… they were well protected).

Anyone that partakes in these kinds of activities is wasting their time. Each store will have a list of serial numbers stored, when they report those numbers to Apple, Steves minions will simply hit a bit kill switch over at Cupertino and the device will cease to function. And thats if you’re lucky.

Photo by Beacon Radio

You see, all current iPhones and iPads come with GPS, built in and active out of the box. Not only can Apple remotely kill these devices but they can also track their location. Simply put, if you are using a stolen iDevice, Apple can find you and will probably guide the police right to your front door.


5 things parents won’t tell you about being a parent —

I’ve been a parent now for just over a year and I feel I haven’t even begun to scratch the surface of the knowledge required to call my self an experienced parent. However, I am learning some things and thought I would share them for the unprepared upcoming and new parents amongst us:

Don't Worry... It's Chocolate (I think)

1) Kids don’t give a shit about shit

If you give a small child the opportunity, they will play with their own shit. Not only will they play with their own shit, they will eat their own shit. They will smear their shit on your cream Walls and rub it into your cream carpet. Kids prefer shit to playdoh and finger paints. Speaking of shit…

2) Nappies are only 90% effective

10% of nappies will suffer from a serious malfunction of structural integrity. Shit will escape up the back and down the legs, piss will seep out of the front and leave your child in a soggy pissy mess. This will happen at inconvenient times such as during Sunday Mass, on the motor way, or while they are sitting on your shoulders.

This was after about 5 days without sleep.

3) Sleep Deprivation comes as standard

I’m sure it’ll stop at some point, but the nippers have a way of destroying your sleep patterns. Whether it’s early starts, late nights or coughing fits in the wee hours. They find a way to destroy your sleep.

Ocassionally my little one will wake up in the middle of the night and refuse to lie back down in his cot, so for an easy life we bring him into our bed and thats where the fun really starts. He likes to spend his evening kicking me, climbing on me and just for good measure, his favourite game is to try and slide his teeny tiny little claws under my back so he can jam them into the most sensitive parts of my skin. Then of course, comes the morning. The slightest noise or crack of sunlight through the curtains is enough to wake the child and once they’re up, they’re up. Until you decide you want to go out, or need to feed them. Then they’ll go back to sleep.

4) Babies get erections

I’m not sure why but I always thought that the common garden hardon was something that didn’t grace a child with its presence until the teenage years. Boy was I wrong. There’s nothing worse than opening a nappy after a malfunction at three in the morning to be greeted by a smiley happy baby boner. Clearly, the child has more exciting dreams than you do.

5) Not so tiny bottom burps

Babies get gas just like adults do. Unlike most adults however, they have little control over when the expunge their noxious fumes. Take for instance, a few months back, we were visiting our estate agent to sign a few papers relating to the house we had just purchased. Our son was sleeping soundly is his pram, when suddenly there was a large gas release from our beloved child. The startled estate agent looked at me and my wife (who was blushing profusely) before coming to the realisation that our lovely son was responsible for the noise and the stench that was rapidly taking over the office. Luckily we were nearly done so we signed the forms and made our excuses followed by a rapid getaway to a less enclosed area before mount stink could erupt again.

 


Wasp Impostors! —

At the moment our lovely office is being invaded with bloody hoverflies! They are completely harmless, but they have me completely on edge because they are black and yellow just like wasps.

Yellow and Black imposters

Every time one flies near me or lands on my desk, my survival instincts kick in and I become immediately cautious just in case I am actually facing a wasp! The other problem is that they seem to like my hair gel as they keep flying into my hair and getting stuck in the spiky jungle that is my noggin!


Review: Game of Thrones – Series 1 —

Before I start this review, I just want to say, I haven’t read the “A Song of Ice and Fire” novels that Game of Thrones is based on. I’m writing purely about the TV show (although, after series 1 I do have a strong desire to read the books!).

Game of Thrones is an medieval tale of Epic proportions set in the Seven Kingdoms of Westeros, where “summers span decades and winters can last a lifetime” following the power struggles of several families as they try to gain control of the kingdom or just live their lives.

I’m not generally a big fan of Medieval type stories and found films like “Lord of the Rings” to be utterly boring even though I enjoyed the books when I was a teenager. Game of Thrones is different, from the first episode I was so captivated that I ended up watching the first ten episodes almost back to back over the course of a weekend. The characters are deep and driven and the actors are believable (with the exception of Sean Bean who while delivering an amazing performance looks a little too much like the wrestler, Triple H for my liking)

Sean Bean or HHH? You decide!

Only one thing outshines the actors themselves, and that is the setting. The scenery and sets are a thing of beauty and really help you believe this was set in a period of great darkness. I was incredibly shocked to find that a large amount of the sets are in fact, virtual. I has just assumed they had found great locations and built amazing sets on them. If that kind of thing interests you, then be sure to watch this video (spoilers!):

Another thing that I like about GoT is that they haven’t made any effort to soften this for the younger generations. There are many scenes featuring full frontal nudity (should have been called ‘game of bewbs’ I swear!), masses of violence and frequent profanities. Even the unmentionable ‘c‘ word gets a couple of outings. Unlike a lot of shows, these things don’t seem forced or out of place – these were violent and opulent times (depending on your class) and I imagine this is how the world really be in these times.

All in all, I really enjoyed Game of Thrones and can’t wait for series two. Here’s hoping we get a few more episodes in it’s second outing as ten episodes flew by too quickly for me. Roll on series two!