This is the OLD WebbyZone archive. Click Here if you wish to check out the all NEW WebbyZone.

Useful WordPress 2.9 Guides

Post image of Useful WordPress 2.9 Guides
Filed in Featured , Web Development 22 comments

WordPress 2.9 – Carmen, named after Carmen McRae, the famous American Jazz singer, was released 4 days back on 18th December, 2009. Taking another step further to remain the most popular blogging platform turned CMS, this release included some exceptionally nice features that could make life really easy, other than of course, the regular bug fixes and security patches.

Some of the most noted features of the new WordPress 2.9 are the global undo/trash feature that lets yous deleted content remain in a trash can for 30 days by default and you can of course restore them within that time, a built-in image editor that allows you to crop & flip your images once uploaded, compatibility checking and batch updating your plugins, and easier video embeds by just pasting the video URLs, but that’s only for YouTube, Daily Motion, Blip.tv, Flickr, Hulu, Viddler, Qik, Revision3, Scribd, Google Video, Photobucket, PollDaddy, and WordPress.tv as of now.

However, some more intricate functions that I really loved were the automatic database optimization support, post thumbnails register for themes and specific category templates not just by ID, like before, but by slug.

Ok, so this post is not about the new features included in WP 2.9 as they are already available everywhere on the net, this one is more about how to use some of the interesting features.

First let’s see how we can use specific category templates with slugs. Earlier we needed to use the id of the categories and in case your blog has a lot of categories, it could just be a little confusing. So now we can use slugs instead – say we have a category WordPress Themes and the slug for the category is wp-themes, then all we need to do is create a template called category-wp-themes.php and upload it. Every time you visit the category WordPress Themes, category-wp-themes.php will automatically show up instead of the default category.php

Next is the database repair and optimization script. Earlier, we needed some plugins or direct MySql queries to repair or optimize the WP databases. Now all we need to do is add

define('WP_ALLOW_REPAIR', true);

in our wp-config.php file. Just open the wp-config.php file with Dreamweaver and add the above line at the end of the file, save and upload. (Be sure to keep a backup.) Then type the URL – http://yourdomain/wp-admin/maint/repair.php to run the script. You’ll get options for either repairing the database or repair and update the database. (Be sure to replace yourdomain with your own domain.)

Moving on to the Trash feature, I have mentioned earlier, and you must be knowing by now, that contents moved to the new global trash bin are kept their for a default of 30 days within which period it can be restored or deleted permanently. Now, some of you might like to disable the trash option completely or maybe like to keep your trashed contents for only 15 days (or some days).  You can configure your trash can from the wp-config.php file again. To disable this feature, copy the following code and paste it in your wp-config.php file -

define('EMPTY_TRASH_DAYS', 0);

In order to keep your contents for some days, say 15 days instead of the default 30 days copy the following code and paste it in your wp-config.php file -

define( 'EMPTY_TRASH_DAYS', 10 );

Thats it, you’re good to set up your trash bin any way you want now!

And finally, you can bid adieu to our beloved timthumb! WordPress 2.9 now has a new thumbnail function and here’s how you can use it.
To activate the feature, check for functions.php file in your theme folder. Open it if it’s there or simply create a blank php file and name it functions. Now add the following code in the functions file -

if ( function_exists( 'add_theme_support' ) )
add_theme_support( 'post-thumbnails' );

Now that the feature is activated, here’s how to add the thumbnail. Once the above code is inserted into the functions file, you can see a new Post Thumbnail box in the WordPress editor view on the right side. This box has a link which says “Set thumbnail”. Click this link and the normal upload media box opens. Go to the Media Library tab and choose an image for using as thumbnail. Once selected, you can now see a new link “Use as thumbnail” appear next to the Insert into Post button. Click the link and your chosen image will be displayed in the Post Thumbnail box and the image will be set as your thumbnail.

Well, now that we know how to activate and add a thumbnail, it’s time to learn how to display the post thumbnail on themes! So in order to display the post thumbs on your theme simply add the following code wherever desired (typically on index.php) -

<?php the_post_thumbnail(); ?>

It is still controversial whether we can use named parameters, but I personally feel it’s worth a try. So if you want to display the default sizes that WordPress automatically creates, i.e. thumbnail, medium or large, here’s what your code should look like -

//Default thumbnail size display
//Should generate same result as the above code
<?php the_post_thumbnail('thumbnail'); ?>

//Medium size image display
<?php the_post_thumbnail('medium'); ?>

//Large size image display
<?php the_post_thumbnail('large'); ?>

Taking the controversy further, I believe only the named arguement thumbnail is not necessary as the snippet itself generates same results, but about the rest of them i.e. medium and large they can be used. However, if we are trying to display thumbnails, why should we need a medium or large image display? Anyways…

The above code will result in the output of a generic <img /> tag with a class “wp-post-image”. So if you want to design your thumbnail visually just go to style.css and define the class e.g.

.wp-post-image {
	padding:3px;
    background-color:#f9f9f9;
    border:1px solid #cccccc;
}

You can also customize your out by adding various arrays in the tag e.g.

/*Over-ride default thumbnail dimensions with 200x200px and add a new class alignleft*/
<?php the_post_thumbnail(array( 200,200 ), array( 'class' => 'alignleft' )); ?>

/*Add another class new_class*/
<?php the_post_thumbnail('medium', array('class' => 'alignleft new_class')); ?>

/*Add more attributes like alt & title */
<?php the_post_thumbnail('medium', array('class' => 'alignleft', 'alt' => 'alttext', 'title' => 'titletext')); ?>

However, while designing themes, you’ll never know the custom sizes your users are going to use. If you use the codes mentioned above, it will override your users custom sizes. If you don’t want to do that, you’ll have to get the custom sizes from the media settings with the get_option() function. Here’s what you can do -

<?php
$width = get_option('thumbnail_size_w') / 2; //get the width of the thumbnail setting
$height = get_option('thumbnail_size_h') /2; //get the height of the thumbnail setting

the_post_thumbnail(array($width, $height), array('class' => 'alignleft'));
?>

/*For medium & large settings and crop checking */
<?php get_option('medium_size_w'); ?> //Width of the medium size
<?php get_option('medium_size_h'); ?> //Height of the medium size
<?php get_option('large_size_w'); ?> //Width of the large size
<?php get_option('large_size_h'); ?> //Height of the large size

<?php get_option('thumbnail_crop'); ?> //Check for crop, On=1, Off=0

We already know that the backward compatible code added in functions.php in the first step to activate the code checks for older version installations and if found, skip the feature. But what if you have a blog for 5 years, have thousands of posts and have used other methods to display thumbnails? Yes you can surely edit each of these posts manually for the next 5 years or simply make the code backward compatible to check first if the feature exists, then if a thumbnail is added using this feature. If both conditions satisfy, return the thumbnail, if not, skip the feature and fallback on other methods used. Here’s how you do it -

if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
	the_post_thumbnail();
} else {
	//Older method comes here
	}
}

That’s all about it. Enjoy Carmen, the new WordPress 2.9 and jazz up your theme designs…

Posted by Ranadeep   @   22 December 2009 22 comments
Tags : , ,

22 Comments

Comments
Dec 23, 2009
8:51 am

I was so excited about wordpress 2.9 but after its release when I updated it, I landed with 2-3 tech issues… I checked into the forum and realize its not only me
other users are facing similar issues…

Author Dec 23, 2009
10:50 am
#2 Ranadeep :

Could you throw some more lights on the matter Harsh? What were the issues? Could they be fixed? I’m using 2.9 and it seems to be doing great for me as of now…

Dec 23, 2009
5:55 pm
#3 Ajay :

Useful tips.

Dec 24, 2009
4:53 am
#4 Jeff :

I am having trouble adding widgets. I have read on the forums that this is a issue that a lot of people are having.

It is giving me this error:

Fatal error: Call to undefined function wp_redirect()

Dec 24, 2009
11:27 am

The post thumbnail is really interesting :D

Dec 24, 2009
3:37 pm
#6 _Gans_ :

Dear Author http://www.webbyzone.com !
The theme is interesting, I will take part in discussion. Together we can come to a right answer.

Dec 25, 2009
11:59 pm
#7 zoranarse :

I want to quote your post in my blog. It can?
And you et an account on Twitter?

Dec 26, 2009
3:42 am
#8 Leo :

Post thumbnails are certainly useful but it’s going to be a pain converting all the old custom fields over.

Jan 9, 2010
2:37 am
#9 Glavniru :

Моя история из жизни: мы как-то с мамой ехали в маршрутке,( мама спец по всем видам мяса на глаз определяет что это), на остановке залазит подвипывший мужик с куском свежака в одноразовом пакете. Едем. Маршрутка резко тормозит,мужик по инерции бежит вперед и пакет рвется ,оттуда выпадет свежак ,дальше мамины слова- ” Мужчина,у вас вымя выпало!” я медленно сползаю под сиденье , пассажиры ржут, мужик красный – выбегает на следующей остановке :) ))

Jan 13, 2010
9:58 pm

here is how u can do it, its the best way

Feb 2, 2010
7:45 pm

Hey very nice blog!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also…

Feb 16, 2010
6:30 am

interesting read. I would love to follow you on twitter.

Feb 21, 2010
10:55 pm
#13 Wahrsagen :

Looks like you are a true expert. Did you study about the theme? hehe

Feb 26, 2010
5:13 am
#14 ddas :

Hi. I actually enjoyed reading your current blog post!. Good quality content. I might advise you to write articles much more often. By doing this, with such type of a helpful site I think that you could rank higher in the search engines :) . I also subscribed for your Rss. Keep up this excellent job!

Mar 28, 2010
11:27 am
#15 Den Relojo :

You are so good to share this. You must be a guru. You could also be a saint! Holy cow!

Oct 30, 2010
5:16 pm
#16 Schedule :

You you could make changes to the webpage subject WebbyZone.com – Useful WordPress 2.9 Guides to something more suited for your content you create. I loved the the writing nevertheless.

Trackbacks to this post.
Leave a Comment

Name

Email

Website

Previous Post
«
Next Post
»
CrossBlock designed by ZenVerse