wp29

A few days ago WordPress 2.9 was made available for download. If you have been using your WordPress administration area you may have noticed the notice at the top: “WordPress 2.9 is available! Please update now”. Being a major release 2.9 could be hiding several new features that will be interesting to investigate and in particular if you’re a Theme Developer you need to how this release will affect your work. It is likely that some of the new feature will make your life easier so why not take a closer look right away?

[exec]$filestr = file_get_contents(‘http://www.tripwiremagazine.com/googleadsensebelowmoretag.inc’);
echo $filestr;[/exec]

WordPress is a very mature open source software product – new releases are well documented and tested. In fact you can read the full list of new features, changes, upgrades, and improvements on the Codex. Lets take a look at the news that stand out and make WordPress 2.9 worth upgrading to.

Post Thumbnails

wp29

WordPress 2.9 comes with interesting new capabilities for supporting Post Thumbnails without the need for custom field hacks. This is great news but for some reason the feature will not be active unless you explicitly turn it on in the functions.php file.

The code part

In order to turn the it on just open functions.php (if it’s not present simply create it) and add the following code:

add_theme_support('post-thumbnails');

If your creating Themes that others may use it is highly recommended to ensure it will run in previous versions of WordPress. Simply use function_exists to achieve this:

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

From the file wp-includes/post-image-template.php you will have 4 new functions available to control rendering of the post image in your theme (was actually called xxx_post_image until recently but a late code change turned image into thumbnail…):

  • has_post_thumbnail()
  • get_post_thumbnail_id()
  • the_post_thumbnail()
  • get_the_post_thumbnail()

Here is an example of how you can check within the loop, if the post has a Post-Thumbnail. If the post have an image it can then be displayed where ever you want:

//insert post thumbnail if present
if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) {
  echo '<a href="' . the_permalink() . '">' . the_post_thumbnail() . '</a>';
}
//else insert image using ex. custom fields
...

The code will output a generic <img /> tag with a class of “wp-post-image” unless you add one yourself. For real backwards compatibility – highly relevant if you update existing themes – you should add an else clause and insert images the old way here.

You have different to control the output. The most simple option is to use the predefined sizes like this but you can also add the attributes available for img as shown on last line:

the_post_thumbnail(); // without parameter gives you a Thumbnail
the_post_thumbnail('thumbnail'); // Also a Thumbnail
the_post_thumbnail('medium'); // Medium resolution
the_post_thumbnail('large'); // Large resolution
the_post_thumbnail('medium', array('class' => 'alignleft', 'alt' => 'alttext'));

// Take full control over thumbnail size
// Here the image will be scaled to to 100x100 pixel
the_post_thumbnail(array(100,100), array('class' => 'alignleft', 'alt' => 'alttext'));

The configuration part

So once your theme has been tuned and is ready to use the latest cools WP2.9 Thumbnail Features you also need to attach an image to you posts to make it work. You simply do this by clicking the Set thumbnail and upload or select existing image. The Post Thumbnail box will be located just below the Categories box.

wp29

Sidebar Descriptions

Widgets are great because they add real flexibility in the themes. On the other hand themes with lots of sidebars can be very challenging to use as it may be difficult to understand where a specific widget will be displayed. With this new feature you will be able to add description to each sidebar that you create in your theme making it more user friendly.

wp29

Adding descriptions to your widget areas is as simple as adding an extra argument to the register_sidebar() function. See example below.

function register_theme_widget_areas() {
  register_sidebar( array(
  'name' => 'Primary',
  'id' => 'primary',
  'description' => 'The primary widget area is used as top right sidebar.',
  'before_widget' => '<li id="%1$s" class="widget %2$s">',
  'after_widget' => '</li>',
  'before_title' => '<h4 class="widgettitle">',
  'after_title' => '</h4>'
) );

Adding a few lines of descriptive text will take a few seconds but will be very important for your theme users.

Image Editor

The WordPress Media Manager has got some really cool new features consisting of two main parts. 1) An image control bar, allowing image rotation, image flips and image cropping. Included with the main WordPress image edit bar are both undo and redo buttons as well. 2) A part for image size and cropping aspects. This not only show pixel size for cropping but allows aspect ratio adjustments. Finishing up the main functions is the ability to adjust images or thumbnails independently and all at once.

wp29


While not being a fully featured image editing system the new Edit Media feature will provide enough control for most users.

Trash

Trash is a new feature and the last step before a permanent delete. You can put a post, image, page into trash, if you don’t want to include them in your posts list.
This new feature will help you recover deletions – could be accidental in an environment with multiple users. It basically enables you to restore posts, pages, comments and attachments that have been trashed at an earlier point in time.

wp29

If you like to configure a special date of how long files should be kept in your trash, you can configure it in your wp-config.php.

define( 'EMPTY_TRASH_DAYS', 10 );

The default settings deletes your content after 30 days. If you don’t want to use trash at all, just use the value 0.

define('EMPTY_TRASH_DAYS', 0);

Media Embed

Makes it easier to embed third-party content such as YouTube videos, etc. Similar to Viper’s Video Quicktags plugin. WordPress will now support oEmbed – a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

wp29

If you don’t like this feature you can turn it off. It will be active by default. By the way it seams like the feature never made it for the release…

wp29

New Templates Based on Slug

This is an important feature for theme developers. In previous versions of WP you had to use a query in your theme or a Plugin to adjust the design or the content to a specific category. WordPress will now support location of category, page and tag templates based on ‘category-slug’, ‘page-slug’ and ‘tag-slug’ respectively. It will also support location based on on ‘category-id’, ‘page-id’ and ‘tag-id’. This means that in stead of making your themes complex and difficult to maintain using:

if ( is_category('somecategory') ) {

to make somecategory render differently you can simply create a template file called category-somecategory.php.

Metadata API

In WordPress 2.9, there is a new Metadata API that can be used to access data from the WordPress meta tables.

The add_metadata() function takes a meta type (‘comment’, ‘post’, ‘user’, etc), the ID of the content type, the key and value of the metadata and whether the information should be unique or not (true or false).

add_metadata('comment', 2535, 'email', '[email protected]');

You can also use update_metadata(), delete_metadata(), get_metadata() and update_meta_cache() for further wrangling. Refer to wp-includes/meta.php for full documentation.

Other

WordPress 2.9 provides more enhancements and features that you should be aware of:

  • Comment Metadata: Metadata for comments is just like it is for posts, pages, and users. Allowing developers to easily highlight comments of various types fx. author comments.
  • Optimize / Repair Database: WordPress has added a new feature which allows you to optimize / repair your database. There are many good plugins providing this vital functionality but now it’s build in. You can activate this function by setting WP_ALLOW_REPAIR=true in your wp-config file.
  • User Registration via XMLRPC: You can now enable user registration through a XMLRPC client
  • Custom Theme Directories: WordPress 2.9 introduces register_theme_directory() which takes a wp-content-relative path and will additionally scan it for themes. Plugins can use this to add themes without requiring copying by the user
  • Batch Plugin Update:You will now be able to upgrade multiple plugins with one click from our WordPress Admin Panel
  • The emoticon system can be altered using the smilies_src hook.
  • If you’re a Theme Developer this post will show you important enhancements in fx. wp_query: Geeky bits in WordPress 2.9
  • JSON compatibility, before only beneficial to PHP 5.2, has been backported for use in WordPress
  • rel=”canonical” for single posts and pages aiding in SEO
  • A new sanitization API (with functions like esc_html())

Anything important missing? Please share your opinion in a comment.

 

Pin It on Pinterest

Shares
Share This

Share This

Share this post with your friends!

Shares
WordPress Appliance - Powered by TurnKey Linux