2011/08/03

WordPress 禁止 the_excerpt 摘要輸出

WordPress 有個函數 the_excerpt
可以讓內容文章使用摘要輸出,
而 WordPress 3.2.1 預設 theme: twentyten,
在 archive 和 search 就是使用摘要輸出。

但摘要輸出有個缺點就是會移除掉 HTML 標籤而變成純文字,
像是超連結和圖片可能都看不到了,而且換行符號也看不到...
而這個 WordPress Theme 一直以來都是大改版的狀態,
各家 Themes 的 designer 只好各顯神通,
找不太到一個正規統一的設計。

後來 Theme 文章迴圈的東西是改到單一 loop.php 來做處裡,
一開始看 archive, author, category, search, tag
怎樣式與 index 的不同?!
後來用半天想說不會要弄這 5 個的 loop 吧~

後來在 loop.php 裡翻來覆去終於找著了,
Only display excerpts for archives and search.
查了 the_excerpt() 這個函數的用途,
原來我早在 2 年 2 個月前就寫過了...

loop.php 段:
[php highlight="1"] <?php if ( is_archive() || is_search() ) : // Only display excerpts for archives and search. ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>[/php]

統統砍掉,改:
[php] <div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->[/php]

archive, author, category, search, tag
顯示的 loop 終於跟 index 一樣了 :)

沒有留言:

張貼留言