将substr()添加到<! - ?php the_title();? - >

时间:2012-08-31 17:12:42

标签: php wordpress

我找到了一些关于将substr()添加到变量而不是函数的教程。到目前为止,html中的输出是:

<div class="symbol"><?php the_title();?></h3> 

当我将鼠标悬停在the_title()内时,Eclipse中会显示以下函数:

function = the_title($before = '', $after = '', $echo = true){
    $title = get_the_title();

    if (strlen($title) == 0 )
        return
    $title = $before . $title . $after

    if ($echo)
        echo $title;

    else
        ...

我只是不确定是否需要在后端页面中添加该功能,或者我可以在前端编写代码。

1 个答案:

答案 0 :(得分:2)

您可以使用wordpress中的函数get_the_title()将当前标题作为字符串返回:

$title = get_the_title();
$title_substr = substr($title, -1);

您不必将标题存储在变量中,您可以直接进入:

$substr = substr(get_the_title(), -1);
相关问题