EEDU Blog: 博客 ·  资讯 ·  论坛 ·  留言
登录 新用户? 注册   |  

ahaoxie's blog

订阅博客:

环境生态网站长

阅读全文

wordpress 首页摘要字数(内容截取方法)

wordpress做博客网站,最影响版面的是首页显示文章内容的全部,无论从美观,还是从SEO优化角度来说,都不是一件很乐观的事,阿杰收集了 几招方法,以改进wordpress首页摘要显示的字数,让wordpress首页内容截取更方便,重点是对index.php中的<?php the_content(); ?>作出修改。

第一:使全部发布的文章显示摘要设置;
通过火狐的插件工具查询到文字区域的class属性,然后再模板文件index.php 中查询class属性对应的位置,将下面的:

<?php the_content( ); ?>替换成下面这句即可。

<?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 290,”…”); ?>

第二:在发布文章时候自助选择添加摘要设置:
通过工具查询到文字区域的class属性,然后再模板文件index.php 中查询class属性对应的位置,将下面的:

<?php the_content( ); ?>替换成下面这句即可。<?php the_excerpt();?>

第三种方法:显示更多阅读标签的替换方式:
<?php the_content( ); ?>替换成下面这句即可。

<h2><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h2>        <?php the_content(__(‘继续阅读 &raquo;’)); ?>接着替换成下面:

<h2><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h2>   <?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 600,”…”); ?> <a href=”<?php the_permalink() ?>” rel=”bookmark”>继续阅读 »</a>

第四种列表页加摘要:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>     <li id=”post-<?php the_ID(); ?>”><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php printf(__(‘Permanent Link to %s’, ‘ctn1′), the_title_attribute(‘echo=0′)); ?>”><?php the_title(); ?></a><span><?php the_time(__(‘y-m-d’, ‘ctn1′)) ?></span></li>

<li>
<?php echo mb_strimwidth(strip_tags(apply_filters(‘the_content’, $post->post_content)), 0, 290,”…”); ?>
</li>
<?php endwhile; ?>
</ul>

以上红色部分是加进去的摘要代码,直接加会出现和标题在同一行上,我们就加了换行标签<li></li>就可以实现了。提供以上四种方法,都可以实现对wordpress 首页摘要字数的限制,打造完美博客。

发表于: 2012-02-11 04:25 | 全文(查看: 3013) | 评论(0) | 本文地址 | 收藏 
分类: 小窍门(95)   标签: wordpress  新知  

"wordpress 首页摘要字数(内容截取方法)" 的评论: (共 0 条)

你对本文的评论:

登录后再作评论
Page was generated in 56 milliseconds