好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

简单分析一下如何调取WordPress的文章摘要 - Word

简单分析一下如何调取WordPress的文章摘要

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> 

查看更多关于简单分析一下如何调取WordPress的文章摘要 - Word的详细内容...

  阅读:49次