You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
<?php
|
|
|
|
class BlogPost extends \Timber\Post
|
|
{
|
|
/**
|
|
* Estimates time required to read a post.
|
|
*
|
|
* The words per minute are based on the English language, which e.g. is much
|
|
* faster than German or French.
|
|
*
|
|
* @link https://www.irisreading.com/average-reading-speed-in-various-languages/
|
|
*
|
|
* @return string
|
|
*/
|
|
|
|
public function reading_time()
|
|
{
|
|
$symb_per_minute = 2280;
|
|
|
|
$symb = strlen(wp_strip_all_tags($this->content()));
|
|
$minutes = round($symb / $symb_per_minute);
|
|
|
|
/* translators: %s: Time duration in minute or minutes. */
|
|
return sprintf(_n('%s ' . pll__('мин.'), '%s ' . pll__('мин.'), $minutes), (int) $minutes);
|
|
}
|
|
public function get_author_name()
|
|
{
|
|
if (get_field('post_author', $this->ID)){
|
|
return get_the_title(get_field('post_author', $this->ID));
|
|
}
|
|
return false;
|
|
}
|
|
public function get_author_img()
|
|
{
|
|
$id = get_field('post_author', $this->ID);
|
|
return get_the_post_thumbnail_url( $id, 'thumbnail' );
|
|
}
|
|
}
|
|
|
|
add_filter('timber/post/classmap', function ($classmap) {
|
|
$custom_classmap = [
|
|
'post' => BlogPost::class,
|
|
];
|
|
|
|
return array_merge($classmap, $custom_classmap);
|
|
}); |