我将标准的Recent Post小部件复制到function.php,我取消注册并注册我的新类 . 在小部件中,我看到这个函数负责显示A标签中最近帖子的 Headers :
<?php while ( $r->have_posts() ) : $r->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php if ( get_the_title() ) {
$t = the_title();
$t = substr($t, 0, 40); /// this doesn't work
}else{
the_ID();
}
?>
</a>
...
...
但是这个substr不起作用 - Headers 总是全部显示 . 我做错了什么?
2 回答
您可以使用mb_substr(),它的工作方式与substr几乎相同,但区别在于您可以添加新参数来指定编码类型,无论是UTF-8还是不同的编码 .
试试这个:
后期编辑:改变
同
您正在使用the_title而不是get_the_title将其提供给特定变量 . 并且一定要在所有这些之后回复$ t .
这一个应该工作