如何使jQuery或WordPress PHP计算字符数,然后找到最后一个空格,并将后面的所有内容替换为“&引用;
我需要限制WordPress自定义字段中div中显示的文本量如何使jQuery或WordPress PHP计算字符数,然后找到最后一个空格,并将后面的所有内容替换为“&引用;,php,jquery,css,wordpress,charactercount,Php,Jquery,Css,Wordpress,Charactercount,我需要限制WordPress自定义字段中div中显示的文本量 <?php $textcount = strlen(get_field('custom_quote')); ?> <?php if ( $textcount > 250 ) : ?> <?php the_field('custom_quote'); ?> <?php else : ?> <?php the_field('custom_quote'); ?>
<?php $textcount = strlen(get_field('custom_quote')); ?>
<?php if ( $textcount > 250 ) : ?>
<?php the_field('custom_quote'); ?>
<?php else : ?>
<?php the_field('custom_quote'); ?>
<?php endif ?>
需要:(351个带空格的字符)→
船头舷窗帕雷尔教务长帆浩笼罩着桅杆
雅尔达姆。Pinnace holystone mizzenmast四分之一鱼窝日本鲈鱼
grog yardarm hempen吊带卷。棉签酒吧闯入者尚蒂
杜布罗右舷格罗格黑杰克舷梯车辙。死灯千斤顶
小伙子纵帆船跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起跳起
脱色
查找250个字符前的空格,然后添加字符串值“…”以代替“”。这样地→
船头舷窗帕雷尔教务长帆浩笼罩着桅杆
雅尔达姆。Pinnace holystone mizzenmast四分之一鱼窝日本鲈鱼
grog yardarm hempen吊带卷。棉签酒吧闯入者尚蒂
右舷梯上的多布卢格黑杰克舷梯
我没有试图限制自定义字段的字符数,因为我需要它在桌面显示器上呈现最大文本,然后限制@媒体上的文本(最大宽度:768px){}
。检查下面的代码
<?php $textcount = strlen(get_field('custom_quote')); ?>
<?php if ( $textcount > 250 ) : ?>
<?php echo wp_trim_words( get_field('custom_quote'), 33, '...' ); ?>
<?php else : ?>
<?php the_field('custom_quote') ?>
<?php endif ?>
获取\u字段()→ get_field()@WasteOfADrumBum Yes已更新。