我将标准的“最新文章”小工具复制到了function.php文件中,取消了注册并注册了我的新类。在小工具中,我看到了这个函数,它负责在A标签中显示最新文章的标题:
但是这个 substr() 函数不起作用 - 标题始终显示全部。我做错了什么?
<?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() 函数不起作用 - 标题始终显示全部。我做错了什么?
$t = the_title();
替换为$t = get_the_title();
。the_title()
将标题输出到屏幕上,不返回任何值。 - hfatahi