2016-11-26 47 views
0

我有下面的代碼,它獲取術語列表並用斜槓將它們分開,例如,mb_strimwidth on implode list

檢驗/檢驗/試驗

我想限制文本28個字符,我試圖使用mb_strimwidth但我得到一個調用未定義功能在函數名的$type_seperated輸出。

<?php 
$term_list = wp_get_post_terms(get_the_ID(), 'type', array("fields" => "names")); 
$type_seperated = implode('/', $term_list); 
if (! empty($term_list)) : ?> 
    <?php echo mb_strimwidth($type_seperated(), 0, 28, '...'); ?> 
<?php else : ?> 
    <?php _e('N/A', 'text-domain'); ?> 
<?php endif; ?> 

這不可能嗎? $ type_seperated輸出是否需要是一個字符串?我該怎麼做呢?

回答

1

確認$type_seperated()函數存在返回字符串。如果你錯誤地使用了parenthesis()然後刪除括號,這意味着它應該像<?php echo mb_strimwidth($type_seperated, 0, 28, '...'); ?>

+0

是的,這是該死的(!我從其他一些使用get_the_title()的代碼中複製了此變量,並且我沒有刪除括號 - 現在工作正常。 – bigdaveygeorge