More formatting goodness for journalists running WordPress Web sites.
And you thought ‘socialism’ was the new ‘N’ word.
Show your pride: Put these badges on your Web site.
According to the Democrats, single-payer is the Democrats’ ultimate goal.

AP Style Dates and Times plugin

Updated Nov. 24, 2009

apcover

I love WordPress, but one of the things that’s always bothered me is the date formats. It’s not WordPress’ fault — php only formats dates and times certain ways. That’s a problem for those of us wanting to adhere to the Associated Press Stylebook. The default php month abbreviations don’t match up, there’s no periods between the letters of am and pm and you really can’t get “noon” and “midnight” to come through.

As more and more journalists take their work online, we should continue to adhere to AP Style. So I wrote up a simple plugin for WordPress to make it work.

Plugin description

This plugin changes the format of the dates and times of your posts and comments to match Associated Press Style. This is perfect for news and magazine sites running WordPress and for those blog writers with a penchant for style consistency

Here’s what it does

  • Adds periods to “am” and “pm” so they become “a.m.” and “p.m.”
  • Removes extraneous zeros when the time is at the top of the hour. “1:00 p.m.” becomes “1 p.m.”
  • Changes “12:00 a.m.” to “midnight” and “12:00 p.m.” to “noon.”
  • Correctly abbreviates months in the date to match AP Style rules. Those are: “Jan.” “Feb.” “March” “April” “May” “June” “July” “Aug.” “Sept.” “Oct.” “Nov.” “Dec.”

Optional features:

  • If the post year is the same as the current year, you can set it to not print the year in the date output to adhere to AP Style rules.
  • If the date of the post is the same as the current date, you can set it to print “today” instead of the date. Technically that’s not an AP Style rule, but a common style nonetheless.
  • You can have it capitalize the words “today,” “noon” and “midnight.”

Therefore, if your post was published at 1:13 in the afternoon on September 22, 2007, this plugin will make the time look like “1:13 p.m.” and date look like “Sept. 22, 2007″

Example

You can see it in action right here on rockmycar. Just look at the post and comment dates throughout the site.

Installation

  1. Download the plugin
  2. Unzip & upload the ap-style-dates-and-times folder to /wp-content/plugins/
  3. Activate in ‘Plugins’ admin menu
  4. Select your options on the plugin admin page

Usage

To use this plugin, you have to edit your template files, replacing WordPress’ default date and time tags with the new ones listed below. You can use it on dates and times for posts, comments and post modified information.

For post dates and times

<?php ap_time(); ?> will print the post’s time in AP Style.
Find the <?php the_time(); ?> tag in your template files (single.php, index.php, search.php, archives.php, page.php, etc.) and replace it with:
<?php if (function_exists('ap_time')) { ap_time(); } else { the_time(); } ?>

Using the if statement will make sure the date is still printed if the plugin is deactivated.

Likewise, <?php ap_date(); ?> will print the post’s date in AP Style.

Find the <?php the_date(); ?> tag in your template files and replace it with:

<?php if (function_exists('ap_date')) { ap_date(); } else { the_date(); } ?>

Here’s how I use it:

I put the time before the date, so my code looks like this:

<?php if (function_exists('ap_time')) { ap_time(); } else { the_time(); } ?> <?php if (function_exists('ap_date')) { ap_date(); } else { the_date(); } ?>

That prints something like 1:15 p.m. Sept. 23, 2008 or noon Sept. 23, depending on the option settings.

For comment dates and times

<?php ap_comment_time(); ?> will print the comment times in AP Style.

Find the <?php comment_time(); ?> tag in your comments template file (comments.php) and replace it with:

<?php if (function_exists('ap_comment_time')) { ap_comment_time(); } else { comment_time(); } ?>

<?php ap_comment_date(); ?> will print the comment dates in AP Style.

Find the <?php comment_date(); ?> tag in your comments template file and replace it with:

<?php if (function_exists('ap_comment_date')) { ap_comment_date(); } else { comment_date(); } ?>

For modified dates and times

<?php ap_modified_time(); ?> will print the post’s modified time in AP Style.

Find the <?php the_modified_time(); ?> tag in your template files (single.php, index.php, search.php, archives.php, page.php, etc.) and replace it with:

<?php if (function_exists('ap_modified_time')) { ap_modified_time(); } else { the_modified_time(); } ?>

<?php ap_modified_date(); ?> will print the post’s modified date in AP Style.

Find the <?php the_modified_date(); ?> tag in your template files and replace it with:

<?php if (function_exists('ap_modified_date')) { ap_modified_date(); } else { the_modified_date(); } ?>

Questions, comments, suggestions

This is a pretty simple plugin, but if you find anything wrong with it, please let me know. Also, if you have suggestions to improve it or comments, don’t hesitate to let them be known.

Changelong

Version 2.0

  • ADDED: Ability to use the plugin for modified dates and times.
  • ADDED: Plugin options admin page.
  • REMOVED: Need to pass parameters with plugin tags. If you’re upgrading from 1.1, the plugin will ignore the parameters set in your template tags and use those you set on the plugin options page.
  • ADDED: Option to print the current year or not.
  • FIX: Plugin now checks for the WordPress UTC offset to set the current timezone when calculating whether the post was posted on the current date.

Version 1.1

  • FIX: Made it so the plugin checked the year when calculating whether the post or comment date was the current date.
  • ADDED: Option to not use “today” when the date is the current date.
  • ADDED: Option to capitalize words “Noon” “Midnight” and “Today”.

Version 1.0

  • Plugin released.

Ready to try it?

box_zipDownload the zip file here.

Donate

This plugin is free and released under a GNU General Public License, but if you found it useful or it rocks your car, feel free to make a donation to keep my beer fund going.


0 Comments

14 Trackbacks

Don’t just sit there, say something!

Name: (required)

E-mail: (required)

Web site: