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