正在查看 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 個帖子)
- 哎呀,回覆話題必需登錄。