wordpress模板标签the excerpt

作者:  耕堂 | 本文浏览671次 | 2009年08月30日

该标签在wordpress中与the content相似。

the excerpt

-描述:
显示当前post的摘要以[...]结尾,并非一个”阅读更多”的链接 。如果在wordpress后台编辑文章是没有指定摘要内容,该标签显示内容的头55个词。摘要内容不会包括html标签和图像。该标签须在循环内。
注意:

若当前文章是个附件,比如在attachment.php和image.php模板循环内,那么只显示它的说明。
-使用:

<?php the_excerpt(); ?>

-参数:

-例子:
1.显示摘要。用在非single页或非链接文章页循环内代替the_cntent显示摘要。

<?php the_excerpt(); ?>

2.在归档页或分类页代替the_cntent。

1)适用于1.5或更高版本:

<?php if ( is_category() || is_archive() ) {

the_excerpt();

} else {

the_content();

} ?>

2)适用于较1.5更低的版本:

<?php if ( $cat || $m ) {

the_excerpt();

} else {

the_content();

} ?>

3.默认摘要显示55个词,下面的代码加入主题中的function.php文件可以改变摘要长度。

function new_excerpt_length($length) {

return 20;

}

add_filter(‘excerpt_length’, ‘new_excerpt_length’);

比较the_excerpt()与the_content()

有时候the_content()更灵活,它可以根据<!–more–>在文章内的随意插入,而显示more之前的内容。
这里有英文原版文档

 右上方更多相关内容/站内搜索-关键词请用空格隔开

  • 标签 :  , ,
  • 原文链接 : http://www.gengtang.net/wordpress/the-excerpt.html
  • 转载原创文章请注明 : 耕堂-gengtang.net
  • 发表留言

    可用HTML标签:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>