A non-profit initiative OF THE

  • WSRI
  • Media Standards Trust

hNews for WordPress

There is a plugin available for WordPress which extra fields to a post for storing hNews specific information. It includes a settings page for adding default values for the fields.

Installing the plugin

  1. Download the hNews for WordPress plugin.
  2. Unzip it into your sites wp-content/plugins directory (other methods of installing plugins are detailed here).
  3. Log into your site admin pages and activate the newly installed plugin.

hNews builds upon the hAtom microformat. Luckily, many wordpress themes already support hAtom, so for these themes most of the work is already done for you.

For example, the default Twenty Ten theme for wordpress 3.0 comes with hAtom as standard.

Adding hNews to an hAtom-supporting theme

You need to make a couple of small modifications to the PHP files which make up your theme. They are found in wp-content/themes/<yourtheme>. You can either edit the files locally in a standard text editor or use the wordpress admin theme editor - the "Editor" link in the "Appearance" admin box.

The exact files you'll need to modify vary from theme to theme, but the important two are the one that displays the posts (e.g. loop.php) and the one which displays a single post on it's own page (e.g. single.php). If you want to be thorough, just search for all the files which contain post_class() or hentry. For each one:

1) add an hnews class to the post, alongside the existing hentry. In most modern themes, this is handled by the post_class template tag, so look through the theme files for:

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

and change it to:

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

For themes that don't use post_class(), you'll instead see something like:

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

Change it to:

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

2) insert code to output the hNews-specific fields - license, principles, dateline (geo) and source organization. This can be done with a single call to hnews_meta(). Just insert this line:

<?php if (function_exists('hnews_meta')) hnews_meta(); ?>

This should be inside the hnews div, and outside the entry-content div (you don't want the hnews data to be treated as part of the content text).

The function_exists test ensures the theme will continue to work even if the hNews plugin isn't installed.

If you're using an off-the-shelf wordpress theme, it's probably worth implementing your hNews-supporting version of it as a child theme. This is easy to do and will make it easier to track any future updates to the original theme.

Adding hNews to a non-hAtom theme

The first step is to modify the theme to support hAtom. An example on how to do that can be found here, and there is a generic hNews howto elsewhere on this site.

After that, just follow the instructions above.