2012-08-31 41 views
0

我找到了一些關於將substr()添加到變量但不添加到函數的教程。在HTML輸出到目前爲止是:將substr()添加到<?php the_title();?>

<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 
     ... 

我只是不確定自己是否需要添加到功能在後端頁面中,或者我可以在前端對其進行編碼。

回答

2

您可以使用該功能get_the_title()在WordPress獲得當前標題作爲字符串返回:

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

您不必存儲在一個變量的標題,你可以直接進入:

$substr = substr(get_the_title(), -1); 
+0

讓PHP找到最近完成的單詞,有12個字符有限(上面的代碼) – lxm7