控制閱讀文章字數
原先的主題在控制板面可以設定字數 但是無法判斷每篇文章的 Read more 設定 因此我自己上網找找後實作成功後 筆記下來
打開佈景主題中的 index.php 後找到
<span class="more">[<a rel="nofollow" target="_blank" href="<?php the_permalink() ?>" title="詳細閱讀 <?php the_title(); ?>" rel="bookmark" target = "_blank">閱讀全文</a>]</span>
在這段程式碼的前面新增下述程式碼應該就可以看到效果了
1 2 3 4 5 6 7 8 9 10 11 12 |
if(is_singular()){the_content();}else{ $pc=$post->post_content; $st=strip_tags(apply_filters('the_content',$pc)); if(has_excerpt()) the_excerpt(); elseif(preg_match('/<!--more.*?-->/',$pc) || mb_strwidth($st)<300) the_content(''); elseif(function_exists('mb_strimwidth')) echo'<p>' .mb_strimwidth($st,0,300,' ...') .'</p>'; else the_content(); |
這段程式碼主要是新增判斷 判斷讀取完 the_content後的內容 是否含有more標籤 如果沒有就使用自訂的字數 300
相逢就是有緣,留下足跡吧!