PureNews

PureNews is an amazingly sleek and powerful news theme with unlimited color variations.

View full feature list Check out the live demo Buy this theme today

Your Theme and WordPress 2.7

Posted by on 23rd Nov 2008 WordPress Coding & Design 16 comments

With the release of WordPress 2.7 just around the corner, it’s time to check on your theme and add in the new functionality available to make the most of it. Also, if you currently offer themes either as free or premium, then these changes are definitely something you need to be adding in.

There are 3 main changes for your theme files to consider – Post Classes, Logout Links and Comment Display.

Post Classes

The first new feature is a new template tag post_class(). This should be used within the loop to replace the class given on each post container, usually a div. You’ve possibly got an opening div within the loop (so it wraps around each post on say the front page) which looks something like

<div id="post-<?php the_ID(); ?>" class="post">

With the new post class feature, we replace the class with the new template tag ie.

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

This addition will then add a number of classes to the div such as post, category-slug, tag-slug (where ‘slug’ is the slug for the category/tag). It will also add the class ‘sticky’ for those that have been made a sticky post in the admin (a new feature of WordPress 2.7).

You can also pass parameters to this function, which will then be added to the class list. So for example, if you wanted to use a class called ‘entry’ (another popular class name with existing themes), you could add this in as a parameter. You can add in multiple additional class names, just separate them with a space eg.

<div id="post-<?php the_ID(); ?>" <?php post_class('entry class2'); ?>>

Logout Link

Most themes have a log out link at least in the comments.php template. Up until now the code for this has been similar to

To logout, <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">click here</a>

This can be found in the comments.php template file, usually just above the comment form.

We now need to change the URL to log out from

<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout

to

<?php echo wp_logout_url(get_permalink()); ?>

The parameter in this function is then read as the redirect URL once the user has logged out, so they’ll be redirected back to the page where the link was clicked.

Note, this doesn’t apply to the meta area that is sometimes found in the sidebar. This link is already toggled between log in and log out (depending on your status) using the wp_loginout() function.

Next week I’ll explain the new features for comments and how to update your theme to work with these. For those who are not already aware, the new features are pagination and comment threading.

  1. WordPress 2.7 Theme Enhancements II
  2. WordPress 2.7 Theme Enhancements III

A PHP Developer using WordPress to power both blogging and commercial CMS sites. I've written and released a couple of plugins for WordPress and am currently writing plugins for use on commercial websites.

16 comments - Leave a reply
  • Posted by Logo Design Blog on 23rd Nov 2008

    I have just published a Logo Design Blog using WordPress and am currently hoping to get some feedback on what I have done so far. So if any of you have the time would be most appreciated as I am new to the world of WordPress and am kind of learning as I go for my blog.

  • Posted by ru4real? on 23rd Nov 2008

    Great info, Sarah …. I've bookmarked this page for use when the new release becomes official.

  • Posted by Link Analysis on 24th Nov 2008

    Haizz… Once it's released, I'm just going to press "Upgrade Automatically". Those coding just gives me headache.

  • Posted by Sarah on 24th Nov 2008

    Upgrade Automatically isn't going to upgrade your theme, it just upgrades the core files i.e. everything besides anything under the wp-content folder. The post above explains 2 very basic changes that will benefit your blog's theme, however as explained, they're not necessary, they're just enhancements to make things easier/better.

    Providing you don't want to use the benefits of the new 2.7 enhancements then keep your theme as it is, no coding changes required :)

  • Posted by Dennis Edell on 24th Nov 2008

    I'll be passing this on to my designer, thanks!

  • Posted by Play Games Win Prize on 24th Nov 2008

    I hate how WordPress is doing this to some of us! lol. They update and we may have to pay to get things fixed.

    -Mike

  • Posted by Sarah on 24th Nov 2008

    Hi Mike, as I've already explained, these are not necessary changes. You don't need to change your theme for WordPress 2.7, just like you possibly didn't update your theme when 2.5 came out.

    They're additional features, extra options you can take advantage of. If you want to, then you can use them and at that point you'd need to make the changes. However to be fair, the two I've listed above would take 5 minutes work so if you want to get them added just post up in the Blogging Tips Forums and someone will help you out.

    However if you have no use for the additional post classes, you're not fussed on the log out link (it's not something I actively use for example) and you won't be wanting to use the new comment features, then you can leave your theme as it is.

  • Posted by bigbox on 11th Dec 2008

    I also try to update my blog to the new released of wordpress and got the errors in my current theme, thank you for your instruction I'll follow that.