Loading...


Loading...

Welcome!

Sign up for a free account, or log in here.

Member Login

You can login by following the link.

Not a Member? Sign up! It's Free!

Please feel free to register.

Click to log in.

1 comment

post_class() and backwards compatibility

There are several good guides to modifying your old WordPress (pre-2.7) themes to the new WordPress 2.7 and they cover pretty much everything. One thing to remember though is that some of the new features and functions added in will only be present with WordPress 2.7.

This is the case with the new post_class() function which adds in class names for the post box. The Codex puts it like this:

The post_class() outputs the class=”whatever” piece for that div. This includes several different classes of value: post, hentry (for hAtom microformat pages), category-X (where X is the slug of every category the post is in), and tag-X (similar, but with tags). It also adds “sticky” for posts marked as sticky posts. These make it easy to style different parts of the theme in different ways.

Adding it the loop in the right place like this:

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

This causes problems when you have a theme that you want to be backwards-compatible with prior versions of WordPress. So you need to change it to this:

<?php if (function_exists(“post_class”)) { ?>
  <div id=”post-<?php the_ID(); ?>” <?php post_class(); ?>>
<?php } else { ?>
  <div id=”post-<?php the_ID(); ?>”>
<?php } ?>

Now it works with previous WordPress versions!

Trackbacks

[...] my implementation of this to allow for backwards compatibilty.  Ran across that tip while search for more info on styling sticky [...]



Leave a Reply



You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


The English Guy on Twitter

Raised Paper WordPress Theme

Raised Paper WordPress Theme screenshot
Theme Price

Onyx WordPress Theme

Onyx WordPress Theme screenshot
Theme Price

Victoriana WordPress Theme

Victoriana WordPress Theme screenshot
Theme Price

Expression Blue WordPress Theme

Expression Blue WordPress Theme screenshot
Theme Price

Premium WordPress Theme Release: Natural Green

Premium WordPress Theme Release: Natural Green screenshot
Theme Price

Theme Release: Ikon WordPress Theme

Theme Release: Ikon WordPress Theme screenshot
Theme Price

Shocking WordPress Theme Release

Shocking WordPress Theme Release screenshot
Theme Price

Digitalis WordPress Theme Release

Digitalis WordPress Theme Release screenshot
Theme Price

WordPress Theme: OpenAir Theme

WordPress Theme: OpenAir Theme screenshot
Theme Price

WordPress Theme: Very English

WordPress Theme: Very English screenshot
Theme Price

News Print v3.0 WordPress Theme Released

News Print v3.0 WordPress Theme Released screenshot
Theme Price

Reclamation WordPress Theme

Reclamation WordPress Theme screenshot
Theme Price