本文章來給大家介紹WordPress獲取文章內容摘要程序代碼,第一個函數是講述了可以獲取所有文章內容摘要,另一個是在首頁只顯示第一個記錄的文章內容摘要.
這個是我自己寫的獲取文章內容摘要程序,代碼如下:
- <?php
- global $more;
- $more = 1; //1=全文 0=摘要
- $my_content = strip_tags(get_the_excerpt(), $post->post_content); //獲得文章
- $my_content = str_replace(array("rn", "r", "n", " ", "t", "o", "x0B","""),"",$my_content); //刪除空格等 如果 不想刪除請直接吧這行前面 加上//
- $my_content = mb_strimwidth($my_content, 0, 500,"..." ); //摘要前500字節
- if (mb_strlen($my_content,'utf-8') < 10){ echo "對不起沒有摘要"; } //少于10字節提示語言
- else echo $my_content;
- ?>
首頁第一篇顯示全文,其他顯示摘要,內容輸出部分改成以下代碼:
- if(!$first){
- $first = 1;
- $more = 1;
- the_content();
- $more = 0;
- }
- else {
- the_excerpt(); //或者使用the_content();
- }
新聞熱點
疑難解答
圖片精選