- WordPress內置的函數(截取的部分用…代替)
echo wp_trim_words( get_the_content(), 66 ); // 文章內容
- PHP函數mb_strimwidth()
<?php echo mb_strimwidth(get_the_title(), 0, 30,"..."); ?>
/*
$str //指定字符串
$start //指定從何處開始截取
$width //截取文字的寬度
$trimmarker //超過$width數字後顯示的字符串
*/
- 使用css代碼來截取
.post-title {
width: 250px;
/* 限制寬度(可選) */
white-space: nowrap;
/* 禁止自動換行 */
word-break: keep-all;
/* 這個也是禁止自動,二選一即可 */
overflow: hidden;
/* 隱藏溢出的內容 */
text-overflow: ellipsis;
/* 溢出文本使用...代替 */
}