The Plugin

The Semantic Classes plugin is a very simple WordPress plugin that adds extra template tags for more semantic blogging. It is inspired by, and borrows some code from, the Sandbox theme by Scott Wallick.

The Documentation

The usage is simple: first, enable the plugin.

There are three possible uses:

Posts

Alter your WordPress template so that inside The Loop, preferably in the container for the post, you include the following template tag:

<?php post_category_class(prefix); ?>
‘category’ returns a space-delinated list of the post’s categories, prefixed with ‘category-‘ by default. Another prefix can be passed as an argument.
e.g. category-personal category-random-thoughts
<?php post_tag_class(prefix); ?>
This function returns a space-delineated list of the post’s tags, prefixed with ‘tag-‘ by default. Another prefix can be passed as an argument.
e.g. tag-politics tag-election-2008
<?php post_author_class(prefix); ?>
This function returns the author name of a post, prefixed with ‘author-‘ by default. Another prefix can be passed as an argument.
e.g. author-Heliologue
<?php post_date_class(prefix, prefix, prefix, prefix); ?>
This function returns a space-delineated list of the post’s date, prefixed with ‘y’ (year), ‘m’ (month), ‘d’ (day), and ‘h’ (hour, 1-24) by default. Different prefixes can be passed as arguments.
e.g. y2008 m03 d11 h12

Body

Alter your WordPress template so that the <body class=""> tag includes the following template tag:

<?php body_type_class(); ?>
This function returns one or more of the following:
‘home’ is the blog’s home page
‘archive’ is an archive page
‘year’ is a yearly archive
‘month’ is a monthly archive
‘day’ is a daily archive
‘date’ is any particular date
‘search’ is a search result
‘paged’ is a paged entry
‘attachment’ is an attachment
‘four04’ is a 404 error page
‘single’ is a single entry
‘category’ is a category archive
‘author’ is an author archive
‘tag’ is a tag archive
<?php body_date_class(prefix, prefix, prefix, prefix); ?>
This function works in two possible ways:
For page types that don’t have a unique date (home, search, 404, category, author, and tag), it will return the current date/time, prefixed with ‘y’ (year), ‘m’ (month), ‘d’ (day), and ‘h’ (hour, 1-24) by default. Different prefixes can be passed as arguments
e.g. y2008 m03 d11 h12
For page types with some kind of single associated date (archives, single entries, etc), it will return that particular date/time, prefixed with ‘y’ (year), ‘m’ (month), ‘d’ (day), and ‘h’ (hour, 1-24) by default. Different prefixes can be passed as arguments. For yearly archives, only the year will be returned; for monthly archives, only the year and the month; for daily archives, the hour will be excluded.

Comments

Alter your WordPress template so that the comment container includes the following template tag:

<?php comment_type_class(prefix); ?>
This function will return a number of possible data:
‘byuser’ if the comment was made by a registered user of the site
‘bypostauthor’ if the comment author matches the author of the entry
‘commentauthor-[username]’ if the comment was made by a registered user of the site, it will return his/her login, prefixed by ‘commentauthor-‘ by default. A different prefix can be passed by an argument.
‘comment | pingback’ depending on the comment type
<?php comment_date_class(prefix, prefix, prefix, prefix); ?>
This function returns a space-delineated list of the comment’s date, prefixed with ‘y’ (year), ‘m’ (month), ‘d’ (day), and ‘h’ (hour, 1-24) by default. Different prefixes can be passed as arguments
e.g. y2008 m03 d11 h12
<?php comment_date_class(alt); ?>
This function will return specified text (‘alt’ by default) for alternating comments.

The License

This plugin is licensed under the GPL.

The Changelog

  • v0.2 – Major expansion
    • Many more functions, including functions for the body and for comments
  • v0.1 – Initial release.
    • Provides three functions: tag classes, category classes, and date classes.
§2003 · By · March 11, 2008 ·


Leave a Reply