Hello!
I need display limited number of characters on website.
I use this code (create shortcode):
add_shortcode('limit_content', 'trim_shortcode');
function trim_shortcode($atts, $content = '') {
$content = wpv_do_shortcode($content);
$length = (int)$atts['length'];
if (strlen($content) > $length) {
$content = substr($content, 0, $length) . '…';
}
// Strip HTML Tags
$content = strip_tags($content);
return $content;
}
And after use this shortcode in "Views":
[limit_content length="300"][types field='cpf-name' output='word'][/types][/limit_content]
It works perfectly, but not correct for "Cyrillic" (Russian).
U can see it on this screenshot - hidden link
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
WEll - It looks like character encoding issue.
Could you please try to use following shortcode (remove the code used before) where I've encode the string to utf8.
add_shortcode('limit_content', 'trim_shortcode');
function trim_shortcode($atts, $content = '') {
$content = wpv_do_shortcode($content);
$length = (int)$atts['length'];
if (strlen($content) > $length) {
$content = substr($content, 0, $length) . '…';
}
// Strip HTML Tags
$content = strip_tags($content);
return utf8_encode($content);
}
Hi Minesh!
Thnx for answer, but after changing I see big problems with encode.
U can see it on screen - hidden link
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Can I have problem URL and access details so I can check whats going wrong there.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Thanks for sharing access details.
I think you missed to share problem URL. Could you please send me problem URL where you've added above shortcode.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I've added another shortcode to limit words as the issue is when word is break due to number of character.
add_shortcode('limit_words', 'trim_words_shortcode');
function trim_words_shortcode($atts, $content = '') {
$content = trim(wpv_do_shortcode($content));
$length = (int)$atts['words'];
$content = implode(' ', array_slice(explode(' ', $content), 0,$length));
// Strip HTML Tags
$content = strip_tags($content);
return $content."...";
}
And you need to use as given under:
[limit_words words="25"][types field='eva-text-kommentariya' output='word'][/types][/limit_words]
I suggest you to apply above shortcode where ever you required.
Awesome!
Thank U very much!