0
我想刮掉我们在文章中的几个字符或文本片段。我们有我们帖子中的故事的日期和来源,但我不喜欢那些包含在我们的摘录中的内容,而且格式化人员坚持认为它必须保留在帖子的顶部。定义Wordpress摘录的开头
我该如何去确切指定我要在帖子中开始的摘录?我可以从<p>
标签开始,还是可以在开始之前设置要跳过的字符数?
任何帮助将不胜感激。这里是我的代码至今:
<phpcode>
<?php $my_query = new WP_Query('category_name=science&showposts=5'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<div id="postlist_container">
<h4 class="und"></h4>
<?php get_the_image(array('image_scan' => true , 'image_class' => 'small_image_left','width' => 80 , 'height' => 80)); ?><div class="post_desc"><date><?php the_time('M j, Y') ?></date> · <a href="<?php the_permalink() ?>">
<?php the_title(); ?></a> <br /><br /><?php the_excerpt_max_charlength(250); ?>
</div>
</div>
<div class="clear"></div>
<?php endwhile; ?>
<?php
function the_excerpt_max_charlength($charlength) {
$excerpt = get_the_excerpt();
$charlength++;
if (mb_strlen($excerpt) > $charlength) {
$subex = mb_substr($excerpt, 0, $charlength - 5);
$exwords = explode(' ', $subex);
$excut = - (mb_strlen($exwords[ count($exwords) - 1 ]));
if ($excut < 0) {
echo mb_substr($subex, 0, $excut);
} else {
echo $subex;
}
echo '[...]';
} else {
echo $excerpt;
}
}
?>
</phpcode>