使用mb_strimwidth函数时不读取加密文章摘要的方法

2011-09-28 | 夜光 | IT记录| 发表评论

使用mb_strimwidth函数可以实现首页index与存档页archive等的文章摘要,但问题是即使文章设置了密码,该函数仍会截取摘要,可以利用wordpress的加密日志函数post_password_required来解决。

原来的首页index.php与存档页archive.php中截取摘要的代码:

<?php echo mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,300,"[......]");?>
<p></p><p><a rel="nofollow" href="<?php the_permalink();?>"><?php _e('Read More&raquo;','YLife');?></a></p>

将其修改为如下代码即可:

<?php if(post_password_required()): ?>
	<?php the_content(); ?>
<?php else : ?>
	<?php echo mb_strimwidth(strip_tags(apply_filters('the_content',$post->post_content)),0,300,"[......]");?>
	<p></p><p><a rel="nofollow" href="<?php the_permalink();?>"><?php _e('Read More&raquo;','YLife');?></a></p>
<?php endif; ?>
本文标签:
本文链接: http://boliquan.com/mb-strimwidth-post-password-required/
版权所有: 玻璃泉, 转载请注明本文出处。

发表评论

您的昵称 *

您的邮箱 *

您的网站

icon_wink.gif icon_neutral.gif icon_mad.gif icon_twisted.gif icon_smile.gif icon_eek.gif icon_sad.gif icon_rolleyes.gif icon_razz.gif icon_redface.gif icon_surprised.gif icon_mrgreen.gif icon_lol.gif icon_idea.gif icon_biggrin.gif icon_evil.gif icon_cry.gif icon_cool.gif icon_arrow.gif icon_confused.gif icon_question.gif icon_exclaim.gif

Protected by WP Anti Spam