在我的分类页面上,有24篇文章的标题和摘录内容。
要显示特定长度的内容,我使用substr 作用现在的问题是,每篇文章的摘录内容都以不同的长度显示。
为了显示特定长度的内容,我使用substr来剪切特定长度的字符串。
$content = strip_tags(get_the_content());
$content = substr($content, 0, 100);
echo $content . \'[..]\';
例如: post title one
post content size post content size post content size post content
size post content size[..]
post title two
post content 1\'50" 0 size post content 55 size post content th[..]
post title three
post content size post "content 55" size checkk post content s[..]
在这个示例中,您可以看到每个帖子都有不同的内容长度。现在我要找的是每篇文章都显示特定长度的内容。第二篇和第三篇文章的内容长度应与first post. 此外,拼写也不应删减。
我已经试过了
$words = explode(\' \', $string, ($word_limit + 1));
if(count($words) > $word_limit) {
array_pop($words);
//add a ... at last article when more than limit word count
echo implode(\' \', $words)."..."; } else {
//otherwise
echo implode(\' \', $words); }
但它不起作用。我需要帮助,以显示相同长度的内容,没有字切断。