Skip to content

Instantly share code, notes, and snippets.

@yckart
Last active December 26, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yckart/7147995 to your computer and use it in GitHub Desktop.
Save yckart/7147995 to your computer and use it in GitHub Desktop.
ProcessWire - ReadingTime Based upon: http://briancray.com/posts/estimated-reading-time-web-design
<?
wire()->addHookProperty('Page::readingTime', null, 'readingTime');
function readingTime($event) {
$page = $event->object;
$words = str_word_count(strip_tags($page->body));
$m = floor($words / 200);
$s = floor($words % 200 / (200 / 60));
$minutes = $m == 1 ? __('Minute') : __('Minutes');
$seconds = $s == 1 ? __('Second') : __('Seconds');
$event->return = "$m {$minutes}, $s {$seconds}";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment