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>