我正在使用此插件显示我帖子的阅读时间:https://jasonyingling.me/reading-time-wp/
然而,我修改了一些东西,因为我希望能够将其用于不同的语言,并改变定位。到目前为止,一切都进展顺利。唯一的小问题是,当阅读时间只有一分钟时,它会显示“分钟”(复数)一词。原来的插件有办法解决这个问题,但由于我正在翻译它,所以无法使用它。据我所知,如果我可以使用插件返回的值,这应该很容易修复,但我不知道如何做到这一点。
以下是我的内容单中当前的显示方式。php文件
<div id="rtime">
<?php pll_e( \'Reading Time:\' ); echo do_shortcode(\'[rt_reading_time]\'); pll_e( \'minutes\' );?>
</div><!-- #rtime -->
这是插件决定是显示“分钟”还是“分钟”的方式,我只是不知道如何将其应用到我的代码中。public function rt_reading_time($atts, $content = null) {
extract (shortcode_atts(array(
\'label\' => \'\',
\'postfix\' => \'\',
\'postfix_singular\' => \'\',
), $atts));
$rtReadingOptions = get_option(\'rt_reading_time_options\');
$rtPost = get_the_ID();
$this->rt_calculate_reading_time($rtPost, $rtReadingOptions);
if($this->readingTime > 1) {
$calculatedPostfix = $postfix;
} else {
$calculatedPostfix = $postfix_singular;
}
return "
<span class=\'span-reading-time\'>$label $this->readingTime $calculatedPostfix</span>
";
}
我曾考虑过修改插件的代码本身,但当新的更新到来时,我会遇到问题,而且无论如何,我不知道该怎么做。提前感谢!