Category Archives: Blogging

WordPress Plugin: FOAF Output

A while ago I hacked WordPres into emitting FOAF, but even though it worked fine, the amount of WordPress-tweaking wasn’t for the faint of heart.

Since then, I have looked a little deeper into WordPress, and now it’s finally ready: The FOAF Output Plugin (view source).

Note: If you want to try running this with WordPress > 1.2, please fix the .htaccess rewrite rule for the author pages like this, otherwise the FOAF file will result in a 404:

RewriteRule ^author/([^/].+)/?$ /<SITEHOME>/index.php?author_name=$1 [QSA,L]

The current version is 1.17 (released 2005-08-31).

Changes since 1.16:
  • Fixed errant line breaks in links.
  • Added generator comment to RSS output.
Changes since 1.15:
  • Added oneline bio on profile page, not HTML-escaped.
  • Added link to RSS channel from author list.
  • Tweaked prefix usage for namespaces.
Changes since 1.14:
  • Added check for array being returned from get_the_category().
  • Added check for get_Lat and get_Long for > 1.2 compatibility.
Changes since 1.13:
  • Fixed category/interest when no categories were found.
  • Changed skos:externalID to dc:identifier.
  • Updated SKOS generation with SKOS extensions vocabulary.
  • Fixed generation of author list URI.
Changes since 1.12:
  • Changed a wrong foaf:made to foaf:page, caught by Ian Davis.
  • Fixed erroneous output of homepage URI on profile page.
  • Fixed a problem with statements being added to Atom feeds, thanks Danny/Sam.
Changes since 1.11:
  • Added blog-wide FOAF output (blogroll) with seeAlso’s to authors’ individual files (example).
Changes since 1.10:
  • Added SKOS output (example) and enhanced RSS output.
  • Added document level RDF/XML API hook, foaf_output_profile_rdf_document, to allow for additional properties by add-ons, e.g. generator information.
  • Fixed possible missing namespace declarations for dcterms in RSS/Atom.
  • Tweaked initialisation code to increase reusability.
Changes since 1.9:
  • Fixed limited interest generation for HTML profile page.
  • Multiple URIs per interest is now handled correctly (if separated by whitespace).
  • Only categories with posts by author are deemed “interesting”.
  • Added bio:olb per B.K. DeLong’s suggestion.
  • Added trust ratings for friends.
Changes since 1.8:
  • Renamed foaf_output_the_date to get_foaf_output_profile_page to better reflect the functionality.
Changes since 1.7:
  • Improved identification of “active” author / user.
  • Now really only shows profile on first archive page, even in paged mode.

Continue reading WordPress Plugin: FOAF Output

Semantic Comments Feeds from WordPress

As hinted to last week, I now have my WordPress installation output comments as RSS 1.0, both as a blog-wide feed and as a feed per post.

At the core they are just like other feeds, but comments are a little more diverse than posts. There are regular comments, entered in the comment form for each post, and PingBack‘s and TrackBack‘s, both of which are “remote” — a notification of reference from somewhere else.

Each of these three types of comments are different from each other, and need to be handled differently.

Continue reading Semantic Comments Feeds from WordPress

WordPress Plugin: Linkifier

To scratch an itch, I’ve hacked a simple plugin, that makes it easier to link to friends and category topics.

When enclosing the name of a friend, a friend’s blog name, or a category name, in {}, the plugin takes care of turning it into a link, including XFN link relations for friends. If a category or link isn’t found for a particular name, a warning will be shown above the post preview in the administration interface, but the text will be left alone.

Now, whenever I link to Danny Ayers, all I have to do is write his name within curly brackets: {Danny Ayers}. Same goes for my {RSS} category: RSS.

Of course, it’s not quite as simple as that, a few prerequisites need to be in order. Luckily, they coincide with the requirements of my FOAF output hack:

  • Categories must have only a URI in their description.
  • Link URIs must be to the weblog of the person.
  • Link name must be the name of the weblog.
  • Link description must be the name of the person.

Download the plugin: Linkifier (rename to linkifier.php and place it in the /wp-content/plugins/ directory)
View source: Linkifier Source

FOAF output from WordPress

Note: Please see FOAF Output Plugin for newer versions of WordPress.

A few days ago, Christopher Schmidt mentioned in a comment that he had been hacking on FOAF export for WordPress. He kindly let me take a look at his work, and in addition posted a message to rdfweb-dev.

In short, he had created a set of dynamic stand-alone profile pages, one with HTML output and one with RDF/XML output using FOAF, in a single file, /profile2.php.

Seeing that, it dawned on me: WordPress already has a “profile” page for each of the authors, likely at /archives/author/<login>/ (depending on the permalink structure defined) — and it even has a template name: the_author_posts_link. In its default incarnation it’s simply a list of the posts by that author, but turning it into a profile page by also showing the basic information and linked friends didn’t seem too hard.

Continue reading FOAF output from WordPress

WordPress presentation hacks

One thing missing from the default WordPress setup is the lack of previous/next links. Fixing this is not really a problem though, as WordPress includes a number of template functions, among which are next_post and previous_post. Both of these take care of all the necessary logic, so that the correct links are displayed, and only when necessary, i.e. only when displaying a single post. I decided to put the links at the top of the post page, next to the post metadata such as categories and author (in the file /index.php):

<div class="meta"> 
    <span class="nav-prev"><?php previous_post('&laquo; %', ''); ?></span> 
    <span class="nav-next"><?php next_post('% &raquo;', ''); ?></span> 
    <?php _e("Filed under:"); ?> <?php the_category() ?> &#8212; <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(); ?> 
</div>

Another thing that I thought would be nice, was only showing excerpts on pages with a large number of posts. This is also quite easy, thanks to the get_excerpt template function:

<?php if(sizeof($posts)>get_settings('posts_per_page')) : ?>
  <div class="storyexcerpt"> 
    <?php the_excerpt(); ?> 
  </div>  
<?php else: ?>
  <div class="storycontent"> 
    <?php the_content(); ?> 
  </div>  
  <div class="feedback"> 
    <?php wp_link_pages(); ?> 
    <?php comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')); ?> 
  </div>  
<?php endif; ?>

Finally, I wanted to fiddle a little with the CSS, styling the posts so that a category specific icon is displayed next to posts in that category. To accomplish this, I had to add some category information to the class attribute of the div containing the post:

<div class="post<? foreach(get_the_category() as $cat){ print(' post-category-'.$cat->category_nicename);}; ?>">

With this in place, the CSS is easily tweaked to display an icon next to the post title (note that only the last one of the rules will be in effect for posts in multiple categories, so ordering is important):

.post-category-wordpress h3 { 
  background: url(/images/wp-button.png) no-repeat right;
}
.post-category-foaf h3 { 
  background: url(/images/foaf-tiny.png) no-repeat right;
}

Improving this approach to be able to handle more than one category icon at a time is left as an exercise for the reader…