As of last month, English language searches on for a person, organisation, or other broad topic will generate a block of in-depth article results, aimed at highlighting the best quality sources.

Note: Google now supports structured data via JSON-LD, which is much cleaner and easier than microdata. I highly recommend Kazuya Takami’s Markup plugin. If you’re still interested in doing it the old way, read on!

To support the feature, they now support HTML5 microdata from the Article schema. Although Google apparently can sniff out suitable content without this additional code, microdata seems like a good way for webmasters to expedite the process and, arguably, improve their odds of inclusion by relieving Google of guesswork.

Article schema sub-types

The Article schema actually has a few, more specific sub-types, namely BlogPosting, NewsArticle, ScholarlyArticle and TechArticle. I don’t know for sure that current support extends to these sub-types; if not it’s surely a logical progression in a rapidly developing area of search.

I posted last year about using post categories in WordPress to determine which schema type is used. I could have just used different templates for different post type, but I’d probably forget and, besides, this way seemed more fun. So it occurred to me to expand my existing technique to pick from the three schemas I’m likely to use: TechArticle, Review and the more generic BlogPosting.

Switching schema on a single WordPress template

I like to put the specific content-type schema right where the actual page content starts (so not on the <body>, for example). That avoids unwanted clashes with other schemas, and makes semantic sense. So all that really needs to be done is switch a single line of code depending on the category the post is in.

In the single.php file, on the opening tag of the <article> element which contains my blog posts, I have the following PHP if, ifelse, else statement:

<article id="post"
<?php if (in_category('Reviews')) {
echo 'itemscope itemtype="" itemref="title"';
elseif (in_category('Tech SEO')) {
echo 'itemscope itemtype="" itemref="title"';
else {
echo 'itemscope itemtype="" itemref="title"';

This tests what category the post is in, and outputs the corresponding itemtype. If it isn’t in either of the first two categories, it defaults to the generic BlogPosting.

Attaching one schema to multiple categories with PHP arrays

If need be, I could give more than one category for each article type by using an array. For example:

elseif (in_category(array('Tech SEO', 'PHP', 'HTML'))) {
echo 'itemscope itemtype="" itemref="title"';

If you’re wondering what the itemref="title" bit is for, that allows me to refer to the itemprop="author" attached to my name in the site’s header, which has the ID "title". This avoids having to re-include my name within the article itself in order to identify myself as the author.