只需创建一个新函数来处理get_the_content()的值,以仅获取最大字数,并在末尾添加一个“Read more”链接:
function custom_single_product_summary(){
$maxWords = 50; // Change this to your preferences
$description = strip_tags(get_the_content()); // Remove HTML to get the plain text
$words = explode(' ', $description);
$trimmedWords = array_slice($words, 0, $maxWords);
$trimmedText = join(' ', $trimmedWords);
if(strlen($trimmedText) < strlen($description)){
$trimmedText .= ' — <a href="' . get_permalink() . '">Read More</a>';
}
echo $trimmedText;
}
好像没用
有人能帮我谢谢