1312月

wordpress自定义首页摘要显示字数

前端开发DIV+CSS, 英文网站建设

wordpress主题首页默认调用网站全文,或者首页文章摘要只显示55个字,下面是几种显示摘要的方法核字数控制
1、使用more标签
在你需要截断的地方(就是你的编辑框)加<!-more->代码.
如果想在正文中隐藏摘要则在文章内容中插入的“<!–more–>”代码后紧接着插入“<!–noteaser–>”代码就可以
小提示:如何在quicktags栏中显示more按钮。
在你使用的theme的index.php中查找<?php the_content(); ?>,如找到,用<?php the_content(__(‘(more…)’)); ?>覆盖。
2、修改index.php文件
使用方法,注意是编辑你的模版中(wp-contant/themes/你的模版/index.php) 文件)。
找到
<?php the_content(__(‘(more…)’)); ?>

<?php the_content(); ?>
修改为:
<?php if(!is_single()) {
the_excerpt();
} else {
the_content(__(‘(more…)’));//或者<?php the_content(); ?>
} ?>
保存
现在你的wordpress,除非打开单个post,其他情况下都是显示摘要。
3、就是可以限定字数
<?php the_content( ); ?>替换成下面这句即可。
<?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 290,”…”); ?>
需要加上查看详情的,就在加上链接
<a rel=”more-link” href=”<?php the_permalink()?>” title=”<?php the_title(); ?>”>查看详情</a>


分享到:



No comments

星期五, 12月 13th, 2013 | 分类:前端开发DIV+CSS, 英文网站建设 | RSS 2.0 | 留言/评论 | Trackback

留言