WordPress native Thickbox

I used to have a separate JQuery plugin for lightbox, until I found this one – Using WordPress native thickbox.

Thickbox

Most of the time, I use the lightbox for gallery purpose. However, that has helped me cut down another JQuery plugins!

After following the tutorial at http://blog.manchumahara.com, that remind me of how I apply the gallery lightbox.

Open functions.php,

Add in gallery file type, the normal extension:

define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);

Add a function for it, so it will automatically add a class to any image that has a link attached with it.

function wp_thickbox($string) {
$pattern = '/(<a(.*?)href="([^"]*.)'.IMAGE_FILETYPE.'"(.*?)><img)/ie';
$replacement = 'stripslashes(strstr("\2\5","rel=") ? "\1" : "<a\2href=\"\3\4\"\5 class=\"thickbox\"><img")';
  return preg_replace($pattern, $replacement, $string);
}

Then add in another function that will automatically add a rel to bulk images. Works for gallery.

function wp_thickbox_rel( $attachment_link ) {
$attachment_link = str_replace( 'a href' , 'a rel="thickbox-gallery" class="thickbox" href' , $attachment_link );
  return $attachment_link;
}

Use add_filter to force the usage:

add_filter('the_content', 'wp_thickbox');
add_filter('wp_get_attachment_link' , 'wp_thickbox_rel');

Full code:

define("IMAGE_FILETYPE", "(bmp|gif|jpeg|jpg|png)", true);
function wp_thickbox($string) {
$pattern = '/(<a(.*?)href="([^"]*.)'.IMAGE_FILETYPE.'"(.*?)><img)/ie';
$replacement = 'stripslashes(strstr("\2\5","rel=") ? "\1" : "<a\2href=\"\3\4\"\5 class=\"thickbox\"><img")';
  return preg_replace($pattern, $replacement, $string);
}

function wp_thickbox_rel( $attachment_link ) {
$attachment_link = str_replace( 'a href' , 'a rel="thickbox-gallery" class="thickbox" href' , $attachment_link );
  return $attachment_link;
}

add_filter('the_content', 'wp_thickbox');
add_filter('wp_get_attachment_link' , 'wp_thickbox_rel');

Done! It works with pages (internal or external), iframe content and even AJAX content. For more information about how to use this plugin, go to: http://jquery.com/demo/thickbox

Sibu, may not be my home anymore…

This time coming home feeling a bit strange. Like, it’s not my home anymore… Not about how boring it is…

Sibu airport

I don’t find any productivity here in Sibu anymore, or maybe all this while.

Too many distraction in Sibu. From “tea time” to “Look at the dog“. Those gaming desktop computers were back here after my brother doesn’t want to stay at the house in Kuching. So there is my gaming zone as well.

That’s why I’m not planning to come back if possible already. At this age, I think I put my priority on my career first, then only my wife. Which is why last night was… Just a movie night. As long as I have a little time, I would rather take a rest than go full force on something doesn’t help my career.

Back in Puchong, real working hours were around 10 hours per day. Here in Sibu, 4 hours top, 6 hours miracle.

Environment Friendly, go green!

Nowadays, we heard too much about getting green, saving fig tree, less paper and etc. All sort of ideas were there. No plastic beg day was good, it’s Monday here in Sibu and Saturday in Selangor and everyday in Penang. I don’t see any point argueing with the policy other than being lazy.

Papers

When those organization telling you about global warming, help environment, they are the freaking on who turned on the air-conditions all day long, printing all kind of papers in the office and etc. They don’t act what they should be, how can ordinary people follow them? Subscribe to help funding them while they keep printing full color magazine and get posted to your door step? The hell with this idea?

Appreciate the toilet

Who doesn’t use toilet? Even the old, they used to built a special one to call them a toilet. In Sibu, all those public toilets are… Really really in a helpless situation.

Public Toilet

From broken bowl to phone numbers to drawing. Maybe that is how we rocks the toilet.

Even though Sibu was promoted to have had the best toilet in Malaysia, one of it kind conceptualized public toilet and so and so. But none of those are really… Functioning.

Why?

Today is my day

Laptop getting my nerve, Internet was used by some unknown person, people leaving to Kuching. To made the matter even worst, people started to work today. So now, I’m alone at home, wondering what to do.

I have made a outline for things to do today. The main priority is to clean up my old work desk! That is what I need the most.

Laptop

Then go to the store to look for some refurbished computers or laptops. Maybe just a research. I still looking for the reason why the screen is flickering. Current research telling me due to the scanning in airport, or maybe not…

Car

Last but not least, car wash items :) It’s been 4 months since the last time I went to Puchong all those cars haven’t even washed yet. It’s going to be a hard work at home.