如果标题长度超过40个字符,我正在修改面包屑脚本以追加'...'
。我把那部分工作做得很好,但是我不能正确的解决的就是如何将它嵌入到这个庞大的脚本中,如果它长度不到40个字符,它就会离开它。嵌套elesif语法
我还需要别的吗?我从来没有遇到过,那里有多个if
个脚本没有else
或elseif
} elseif (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo '<a href="' . $homeLink . '/' . $slug['slug'] . '/">' . $post_type->labels->singular_name . '</a>';
if ($showCurrent == 1) echo ' ' . $delimiter . ' ' . $before . substr(the_title('', '', FALSE), 0, 40) . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
$cats = get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
if ($showCurrent == 0) $cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
echo $cats;
if (($showCurrent == 1) && (strlen($post->post_title) > 40)) echo $before . substr(the_title('', '', FALSE), 0, 40) . '...' . $after;
} elseif {
if (($showCurrent == 1) && (strlen($post->post_title) < 40)) echo $before . get_the_title() . $after;
}
这不会解决您最实际的问题,但我用了这种情况的东西是在服务器上,我检查字符串的长度为> 40(像你这样做)......如果是这样,加一个类的元素叫做“trimmed”,只打印前40个字符......然后在你的CSS中使用这个规则:'.trimmed:after {content:“...”; } – Ian
整洁的技巧,谢谢分享 –