是否有可能不切断文本文本中间的WordPress摘录博客文章?
网址: 有些文章的摘录在节录结束时中间截断了,所以字母的长度减少了一半。(示例3向下)由于我定义了一个高度,紫色标题可以是1、2、3或4行加上常规复制文本,因此会产生不同的高度是否有可能不切断文本文本中间的WordPress摘录博客文章?,wordpress,Wordpress,网址: 有些文章的摘录在节录结束时中间截断了,所以字母的长度减少了一半。(示例3向下)由于我定义了一个高度,紫色标题可以是1、2、3或4行加上常规复制文本,因此会产生不同的高度 有什么办法可以帮上忙吗?因为这是因为标题跨越3行-一种可能的方法是检查标题有多大,然后从那里调整摘录 因此,在functions.php中 这将调整摘录的大小-如果标题跨越3行,则将其设置为您想要的大小 function excerptlength($length) { return 50; //enter yo
有什么办法可以帮上忙吗?因为这是因为标题跨越3行-一种可能的方法是检查标题有多大,然后从那里调整摘录 因此,在functions.php中 这将调整摘录的大小-如果标题跨越3行,则将其设置为您想要的大小
function excerptlength($length) {
return 50; //enter your desired ammount
}
function short_excerpt($length_callback='excerptlength') {
global $post;
if(function_exists($length_callback)){
add_filter('excerpt_length', $length_callback);
}
$output = get_the_excerpt();
$output = apply_filters('wptexturize', $output);
$output = apply_filters('convert_chars', $output);
echo $output;
}
然后添加这个-它计算标题的大小,如果超过70(或您想要的数量),那么摘录将显示我们在上一个函数中设置的摘录的自定义大小
function custom_excerpt(){
$title = get_the_title();
$limit = "70"; //enter your desired ammount
$more="...";
if(strlen($title) <= $limit) {
the_excerpt();
} else {
short_excerpt();
}
}
在上发布查询以使用此代码。
20(替换您定义要显示的字数)
在css style_main.css第97行:
.入职{
浮动:左;
最大高度:128px;
溢出:隐藏;
宽度:515px;
}
删除:
最大高度:128px;
溢出:隐藏;
查看wordpress提供的更多
标签:
<?php custom_excerpt(); ?>
your post Query on <?php the_content(); ?> to use this code.
<p><?php $words = explode(" ",strip_tags(get_the_content()));
$content = implode(" ",array_splice($words,0,20)); echo $content; ?></p>
<?php if($words): ?>
<p class="more"><a href="<?php echo the_permalink();?>">Read More</a></p>
<?php endif;?>
on your css style_main.css line 97:
.post .entry {
float: left;
max-height: 128px;
overflow: hidden;
width: 515px;
}
remove :
max-height: 128px;
overflow: hidden;