在functions.php文件中写入下面截断题目字符的函数
1 2 3 4 5 6 7 8 9 | function TruncateTitle($max_length) { $title_str=get_the_title(); if(mb_strlen($title_str,'utf-8')>$max_length) { $title_str=mb_substr($title_str,0,$max_length,'utf-8')."..."; } return $title_str; } |
调用相关分类下的文章 ,使用该函数
1 2 3 4 5 6 7 | < ?php $posts = get_posts( "category=3&numberposts=5" ); ?>
< ?php if( $posts ) : ?>
< ?php foreach( $posts as $post ) : setup_postdata( $post ); ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="< ?php the_title(); ?>">
< ?php echo TruncateTitle(9); ?>< ?php the_time('Y-m-d')?></a>
< ?php endforeach; ?>
< ?php endif; ?> |
简单的说明一下:category=[指定分类ID],numberposts=[显示的文章数]


