Create TimThumb IMG-tags with correct with and height attributes with this simple function for WordPress
TimThumb is a nice PHP-script that resizes image.
I’ve written a function for WordPress that takes the ID of an attachment and returns a full img-tag, including the correct width and height attributes, together with all required TimThumb arguments of course.
With no width and height values set, the page will be redrawn several times, resulting in a very ”jumpy” page. Using this function to create your image tags will solve this problem.
Also, if you don’t have any width and height atributes in img-tags it can lead to errors when JavaScript ondomready calculations are made, beacuase sometimes the images are still loading and therefor JavaScript can’t determine the width or height of the images.
Usage
<?php
// echo a complete img-tag where the image will be resized to a width of 100px
echo ma_image_thumb("id=123&w=100&tag=1");
<pre>// echo a complete img-tag where the image will be resized to 75x75, and add the alt attribute
echo ma_image_thumb("id=123&w=75&h=75&tag=1&alt=Image alternative description");
</pre>
?>
The function
/*
* Get the source for a resized image
* if args["tag"] is true then a complete img-tag including width and height is returned
*
* @requirement timthumb.php must be in /<your-template-path>/inc/timthumb.php
* @param array/querystring $args. required are id = the post id for the attachment
* @return string Complete image tag or just the value to be used as src
* Align:
* c : position in the center (this is the default), t : align top, tr : align top right, tl : align top left, b : align bottom
* br : align bottom right, bl : align bottom left, l : align left, r : align right
*/
function ma_image_thumb($args = "") {
$defaults = array(
"w" => "0",
"h" => "0",
"q" => 75,
"a" => "c", // align
"alt" => "", // alt-attribute
"tag" => false, // return scr wrapped in tag?
"id" => null, // get src from file
"src" => null
);
$args = wp_parse_args($args, $defaults);
$out = "";
$file_id = (int) $args["id"];
if ($file_id) {
// $post_file = get_post($file_id);
if (!$file_id) {
return "";
}
$src = wp_get_attachment_url($file_id);
} elseif ($src) {
// already a path..
// @todo: this!
return "";
}
$w = (int) $args["w"];
$h = (int) $args["h"];
$q = (int) $args["q"];
$a = $args["a"];
// TimThumb
$thumb_src = get_bloginfo("template_url") . "/inc/timthumb.php?w=$w&h=$h&a=$a&q=$q&src=$src";
if ($args["tag"]) {
// Get original width and height
$image_info = wp_get_attachment_metadata($file_id);
$width = $image_info["width"];
$height = $image_info["height"];
$new_width = $w;
$new_height = $h;
// generate new w/h if not provided
if ($new_width && !$new_height) {
$new_height = $height * ($new_width / $width);
} elseif ($new_height && !$new_width) {
$new_width = $width * ($new_height / $height);
} elseif (!$new_width && !$new_height) {
$new_width = $width;
$new_height = $height;
}
$alt = $args["alt"];
$out = sprintf("<img src='%s' alt='%s' width='%d' height='%d' />", $thumb_src, $alt, $new_width, $new_height);
} else {
$out = $thumb_src;
}
return $out;
}
iPhone 4: underbar så länge du inte försöker ringa
Man brukar ju skämta lite om moderna telefoner med alla sina funktioner genom att ställa frågan ”går det att ringa med den också?”
Faktum är att det gått så långt nu så det blivit sanning. Sedan ett par veckor tillbaka har jag en iPhone 4. Sammanfattningsvis är den helt underbar: fantastisk skärm, snabbare att jobba med, möjglihet till att spela musik samtidigt som man surfar eller SMS:ar. En perfekt partner när man är ute och reser eller går.
Om det inte vore för det här med att ringa då.
Uppskattningsvis var tredje samtal avbryts mitt i. Ibland med ett liten tut-tut-tut-ljud som signalerar att något är fel, ibland utan ljud alls. Den sista är den som är mest jobbig: jag kan stå och prata med någon och så märker jag efter en stund att personen i andra luren inte svarar eller ”hummar” när jag pratar. Och jodå, samtalet har blivit avbrutet och jag har pratat med mig själv i en minut eller två. Oerhört jobbigt. Och pinsamt när jag pratar på för fulla muggar och så ringer plötsligt telefonen! Folk runt omkring mig måste tro jag är tokigt eller att jag bara låtsas prata med någon. Pinsamt, som sagt. Och irriterande och frusterande.
Dessutom så slås funktioner på hux-flux. När jag pratar med någon så sätts ibland högtalartelefonen på, ibland aktiveras mute-knappen. Och ljudet! Det är som att höra dom andra prata i en burk i Afghanistan. Verkar särskilt gälla samtal från en iPhone 4 till en iPhone 4. Vafanliksom..
Men i övrigt; suverän telefon!
View your pages directly in the admin area menu with this new WordPress plugin
Can’t believe I haven’t told you about my new plugin yet! It’s so good that I can’t use a WordPress installation without it. That’s pretty good for a plugin that’s still in version 0.1! ![]()
Ok, it’s called Admin Menu Treee Page View and it will display all your pages direcly in the WordPress admin menu. And when I say directly, I mean directly: no need to click ”pages” and no need to click the Tree Page View (still a good plugin though!).
This is very good for CMS-like installations of WordPress, where you have many pages in a hierarchy. After using WordPress for our clients for a while I noticed that I really hated to have to go to a new page just too see all my pages. It was very cumbersome to change the current page to edit. Also, I would often forget where in the page hierarchy I currently was.
I really needed a way to always show the pages, no matter where I was in the admin area. And the result is simple but very effective. Just take a look at this screenshot and you will understand:

See! All the pages, visible while editing an article. Wanna edit another article? Just click on it.
If you use WordPress as a CMS you will love this plugin. Give it a try and then let me know what you think.
Download from wordpress.org: http://wordpress.org/extend/plugins/admin-menu-tree-page-view/