正在查看 2 个帖子:1-2 (共 2 个帖子)
-
作者帖子
-
薇晓朵博客改版重启使用,需要严肃对待优质内容,所以把各方面的参数需要调整公布下,显示效果如下:
效果如下
function reading_time_shortcode( $atts ) { $post_id = get_the_ID(); $post_content = get_post_field( 'post_content', $post_id ); $word_count = preg_match_all( '/[\p{L}\'\-]+|\p{Han}+/u', $post_content, $matches ); $reading_time = ceil( $word_count / 200 ); // Assumes an average reading speed of 200 words per minute return '<p> 预计阅读时间:'.$reading_time.' 分钟</p>'; } add_shortcode( 'reading-time', 'reading_time_shortcode' );
调用简码输入
[reading-time]
我们因为需要添加 CSS 小图标就给代码加了个 class 如下
function reading_time_shortcode( $atts ) { $post_id = get_the_ID(); $post_content = get_post_field( 'post_content', $post_id ); $word_count = preg_match_all( '/[\p{L}\'\-]+|\p{Han}+/u', $post_content, $matches ); $reading_time = ceil( $word_count / 150 ); // Assumes an average reading speed of 200 words per minute return '<p class="reading-time"> 预计阅读时间:'.$reading_time.' 分钟</p>'; } add_shortcode( 'reading-time', 'reading_time_shortcode' );
添加到需要显示的地方就行。
-
作者帖子
正在查看 2 个帖子:1-2 (共 2 个帖子)
- 哎呀,回复话题必需登录。