23/01/07
hReview in Textpattern
That last post was a little test in using the hReview Microformat in Textpattern. I think it worked!
One of Textpattern’s great features is the ability to use a different ‘form’ (the template that specifies how posts are marked up) that each post uses. With this in mind, all you need to do is create a different article form called ‘hReview’ and specify that any time you do a review on a Textpattern blog.
I’ll come to the actual markup of the form in a moment, but first I just want to show you how I’ve used the Content > Write tab to write the review.
In this example, all I added were 2 custom fields (via Admin > Preferences > Advanced), ‘URL’ and ‘Rating’, but you may want to add more for fields such ‘Item Type’.
Then I entered the review as follows:
| TXP Field name | Microformat Class | TXP Tag |
| Title | Item | <txp:title /> |
| Excerpt | Summary | <txp:excerpt /> |
| Body | Description | <txp:body /> |
| Article Image* | Photo | <txp:article image class="photo" /> |
| Rating (custom field) ** | Rating | <txp:custom_field name="Rating" /> |
| URL (custom field) | URL | <txp:custom_field name="URL" /> |
*The Textpattern ID of the image
**Entered as a number from 1-5
I then chose ‘hReview’ from the ‘Override form’ dropdown before publishing. However, you can’t choose that until you create the form, so let’s get down to the nitty gritty! Create a new form called ‘hReview’, choose ‘article’ from the type dropdown, and add the following code:
<div class="hreview">
<h2 class="item"><txp:permlink class="fn"><txp:title /></txp:permlink></h2>
<p><abbr class="dtreviewed" title="<txp:posted format="%Y%m%d" />"><txp:posted format="%B %e, %Y" / ></abbr>
<span class="reviewer vcard"> by
<span class="fn"><txp:author /></span>
</span>
<txp:if_custom_field name="URL">
<p><strong>Website:</strong> <a href="<txp:custom_field name="URL" />" class="fn url" rel="bookmark"><txp:custom_field name="URL" /></a></p>
</txp:if_custom_field>
<div class="summary">
<txp:excerpt />
</div>
<div class="description">
<p>Rating: <span title="<txp:custom_field name="Rating" />" class="rating"> <txp:custom_field name="Rating" /></span> out of 5</p>
<txp:article_image wraptag="p" class="photo" />
<txp:body/>
</div>
</div>
A lot of this is self-explanatory. The review description is output wherever you put <txp:body />, the item name is output wherever you put <txp:title />. There are a few places where it’s probably worth talking through what’s going on.
Date
The txp tag @23.01.07 has an attribute “format” which allows you to customise the date using PHP’s strftime strings:
<abbr class="dtreviewed" title="<txp:posted format="%Y%m%d" />"><txp:posted format="%B %e" />, <txp:posted format="%Y" />
Doing this uses the published time information and displays in ‘human readable’ form:
< txp:posted format="%B %e, %Y" / >
as well as ISO for the title attribute:
<txp:posted format="%Y%m%d" />">
Handy if you also want to use Textpattern to display events in hCalendar format (which I’ll cover in another post).
Rating
Whatever number is entered into the Rating field is output in the title attribute as well as the text:
<p>Rating: <span title="<txp:custom_field name="Rating" />" class="rating"> <txp:custom_field name="Rating" /></span> out of 5</p>
There are other possibilities here, such as: class="rating star<txp:custom_field name="Rating" />" and then using image replacement to style the span with the resulting class name (star1, star2 etc.). The hReview creator suggests using HTML entities to display a star rating, for which we’d need to use the conditional tag <txp:if_custom_field>, e.g:
<txp:if_custom_field name="Rating" val="1">★☆☆☆☆</txp:if_custom_field>
This is what I used on the first review, but as Mr Oxton pointed out, this isn’t very ‘human readable’ to things like screenreaders, so I intend to implement the image replacement/class method above.
It’s a wee bit of sweat to set it up, but you have, you’ve got a form that can be called up anytime you want a review on your site to be marked up as a hReview!
21
Tags: 


Previous





Download our vCard
Silus Grok said 623 days ago:
What other microformats does Textpattern support, pray tell?
Jon Hicks said 623 days ago:
Any of them. Thats the point, Microformats are just class names, so just as with any flexible CMS, you make it use whatever markup you want. The point here is that once you’ve created this form, you can specify to use that rather than the default one, on a per-article basis.
Silus Grok said 623 days ago:
Ah! Very good.
Thanks!
Joshua Brewer said 623 days ago:
First – this is sweet. I was thinking about doing this for hCards/hCal the other day. Great tips on how to implement.
Second – When browsing the previous article in Firefox w/ Operator the hreview is invalid b/c it is missing the fn of the product.
At least that is what the error report tells me.
Cheers.
JamieKnight said 623 days ago:
hiya,
Thanks for the tips, I have allredy got a hCard implimentation on my site using text pattern and the form_output tag. I have made it sit in the footer, and soon i shall be adding a ling to make the footer exampnd to reveal the hCard formated goodness.
Will definitly be adding this idea,
Jamie Knight
(^licks^)
Kuswanto said 623 days ago:
Very informative, i think i am going to use it and write some review.
matthew said 623 days ago:
Nice implementation. When the new Calendar Plugin (in testing) is ready for release, it will be able to use hcal/ical microformats for integration into outlook or ical.app, etc.
I hope we can pull together something as clean as this. Are you planning on adding this to the forum examples?
Robert Wetzlmayr said 623 days ago:
One additional suggestion:
txp:posted’s format string is not restricted to just format specifiers but can also containt just plain text, so you could combine your human readable date representation (currently < txp:posted format="%B %e" / >, < txp:posted format="%Y" / >) into one tag as well: < txp:posted format="%B %e, %Y" / >
Andy Croll said 623 days ago:
Jon once again, you appeared to have solved the TXP problem I was working on for my own site. I’m just going to put it down to magical mind-reading powers.
Then try and implement on my own site over the next couple of days.
Andy Higgs said 623 days ago:
Cheers Jon – that’s bridged necessary gap I’ve been wanting to bridge for a long time!
Sam said 623 days ago:
Thanks for tip, your form code looks very useful!
Monica said 622 days ago:
Rather useful thing this Textpattern. I’ll try to implement it.
Andy Yeates said 622 days ago:
Jon,
Been a lurker for a while reading the feeds but thought i’d make an appearance and post a comment to say cheers for the textpattern hreview goodness.
Bit of a fan of textpattern myself, but find the oodles of plugins a bit hard work. Can i be a little cheeky and ask what textpattern plugins you used (assuming you did) to do your booklist, playlist and flickr features.
Cheers.
Andy
Clive Walker said 622 days ago:
There’s also a microformats Textpattern plugin that provides an alternative approach for adding hReview and other microformats to Textpattern.
Genia said 621 days ago:
JamieKnight, what’s about your review? Is it ready? I want to read it, before use
Gerard McGarry said 620 days ago:
Good post Jon and a fairly straightforward implementation of a microformat. I know there are plugins for WordPress to do the same sort of thing, but this actually seems a little bit more elegant.
Is it just me, or do you wish there were more reasons to use microformats out there? I get the feeling that we’re about 5-10 years ahead of our time on this one!
Joshie Surber said 620 days ago:
s/article image class=”photo”/article_image class=”photo”/g
Destry Wion said 618 days ago:
Nice tip, Jon. Anytime I can use Txp core and avoid a plugin, I like to (though we all agree, I’m sure, there are some indispensable plugins available).
I found Alex Faaborg’s series on microformats for Firefox 3 (e.g., Part 2 of the series), to be a well-reasoned look at which ones hold real weight on a wide-scale (namely, hCard, geo, and hCalendar), but your use of hReview is an hLovely example of a localized application.
P.S. Came across this site via 456 Berea, notice anything subtlety familiar?
Eric Fields said 616 days ago:
Looks nice…
The last time I used TextPattern—about 1.5 years ago—I hated the fact that the CSS was stored in the database. I’m sure this was optimal but editing CSS within a form was painful, as I’m much more of a edit local -> upload to production kind of guy who makes small tweaks by editing via FTP. Has this changed over time? Do people not find this frustrating? share!
Jon Hicks said 616 days ago:
Eric – you don’t have to use the inbuilt CSS system. Just upload your local CSS files and link to them either in the page template with the standard link tag, or by putting an @import to the file in the textpattern css.;
Marko Mihelcic said 613 days ago:
Great article Jon,
I’m using the pnh_mf plugin at the moment for txp, it’s pretty neat but in some cases it’s best to self code it.
http://placenamehere.com/TXP/pnh_mf/