小编Cri*_*n N的帖子

如何在Wordpress中实现估算的阅读时间功能?

我正在尝试将估计的阅读时间整合到wordpress主题中,但似乎无法正常工作。我从这里http://wptavern.com/estimated-time-to-read-this-post-eternity获取代码。我将其粘贴到functions.php

function bm_estimated_reading_time() {

    $post = get_post();

    $words = str_word_count( strip_tags( $post->post_content ) );
    $minutes = floor( $words / 120 );
    $seconds = floor( $words % 120 / ( 120 / 60 ) );

    if ( 1 < = $minutes ) {
        $estimated_time = $minutes . ' minute' . ($minutes == 1 ? '' : 's') . ', ' . $seconds . ' second' . ($seconds == 1 ? '' : 's');
    } else {
        $estimated_time = $seconds …
Run Code Online (Sandbox Code Playgroud)

php wordpress

3
推荐指数
1
解决办法
1052
查看次数

标签 统计

php ×1

wordpress ×1