the_excerpt()標簽
該標簽顯示當前文章的摘要,摘要之后帶有[...]符號,如果發布文章時沒有提供摘要(在文章編輯界面下方的摘要字段中填寫摘要),WordPress會自動截取文章的前55個單詞作為摘要,這個的摘要長度可以自由更改,但是不是很方便,還需要使用過濾器進行設置,如果多個摘要長度不同挺麻煩的,具體可以參考WordPress文檔中的the_excerpt()標簽。
the_content()標簽
若文章使用快速標簽 來截取摘要,the_content()標簽將只在非單篇文章或非固定鏈接文章上顯示 前的摘要部分,the_content()標簽可包含一個規定 內容和樣式的參數,該參數會生成“繼續閱讀全文”的鏈接。
如果沒有設置,則會默認顯示全文,有點嚇人,不是很實用。
真正符合中國人的使用方式:
- <?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 150, '...'); ?>
mb_strimwidth(),這篇文章有這個函數的介紹的,這樣我們就可以自由的調取摘要,并且不受the_content() 的干擾,并且摘要中不會出現亂碼.
完全的使用案例:
- <ul class="excerpt">
- <?php while (have_posts()) : the_post();?>
- <li>
- <a href="<?php echo get_permalink(); ?>" class="pic"><?php dm_the_thumbnail(); ?></a>
- <h2><a href="<?php the_permalink() ?>" title="<?php mb_strimwidth(the_title(),0,1,'...'); ?> - <?php bloginfo('name'); ?>"><?php mb_strimwidth(the_title(),0,1,'...'); ?></a></h2>
- <div class="info">
- <span class="time"><?php the_time('m-d');?></span>
- <a class="comm" href="<?php comments_link(); ?>" title="查看 <?php the_title(); ?> 的評論"><?php comments_number('0', '1', '%'); ?>人評論</a>
- <span class="view"><?php if(function_exists('the_views')) the_views(); ?>次瀏覽</span>
- </div>
- <div class="note"><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 150, '...'); ?></div>
- </li>
- <?php endwhile; ?>
- </ul>
新聞熱點
疑難解答
圖片精選