首页 开发指南

说100种方法,不如告知一个可行的方法!

很多时候,我们都需要文章摘要这个功能,当然,官方也有这样的函数,比如:the_excerpt(),这个函数要求我们每次发表文章的时候,都给摘要这个字段里面写一段话,按照wordpress的设计初衷来说,这样的设计原本是极好的,不过,我们的用户很多时候都是懒散的,面对这样的用户,他们自然会提出更“无赖”的要求,不过仔细想来,还是有方法可以实面的。

首先,我们先了解两个函数:

the_content()

其功能是直接输出文章的内容,其实是相当于echo ……;

get_the_content()

这个函数的返回值是的一个$output

然后我们再看下面的代码:

?<dl>
<dt><a href="/?cat=3">NEWS</a></dt>
<?PHP
query_posts("cat=3&orderby=date&order=ASC&posts_per_page=3");
if (have_posts()) :
while (have_posts()) : the_post();
?>
<dd>
<div>
<p><span><?php the_time('Y.n.j'); ?></span><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p>
<?php
$content=strip_tags(get_the_content());
echo mb_strimwidth($content,0,150,"...");
?>
</div>
</dd>
<?php endwhile; ?>
<?php else : ?>
<dd><p align="center">没有数据。</p></dd>
<?php endif; ?>
<dd>
<div>
<a href="/?cat=3">VIEW MORE NEWS<span>></span></a>
</div>
</dd>
</dl>

这样就实现了。里面用到几个函数,这里不解释了,自己翻文档去吧!

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

会员评论:(0)

声明:本站所有主题/文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除,谢谢!
©www.sbmzenith.com 2013-2022 All Rights Reserved.
豫ICP备15009393号