Digital experiences for all disciplines
New Landing › How can we help? › Atelier › Excerpt length setting is not working with Chinese
New Landing › How can we help? › Atelier › Excerpt length setting is not working with Chinese
- This topic has 14 replies, 5 voices, and was last updated 7 years by David Martin – Support.
-
Posted in: Atelier
-
May 23, 2016 at 9:17 am #269271
Dear Support team,
I was playing around with the excerpt length option in the “recent post” module, and found it is not working. Finally I find out the problem is that it only count the English words but ignore the Chinese characters. Is there any chance I can fix it? (Please see the attached screencapture.
Thanks!
Hong
Attachments:
You must be logged in to view attached files.May 25, 2016 at 9:53 am #269958sorry, but I have been waiting for 2 days, is there anyone can help me please? Thanks!
May 25, 2016 at 10:34 am #269975Hi,
Apologize for the delay. Will have to forward this situation to our head developer because it seems it’s a general issue in WordPress.
-Rui
May 25, 2016 at 3:54 pm #270123Thanks for the heads up, we will resolve with the next update. Reference: http://wptutorial.narrativecard.com/wordpress-excerpt-problem-chinese/
– Ed
March 21, 2017 at 5:38 am #317841Hi!
May I know the status of this issue?
I got the same problem…
I search around and found this plug-in to solve this issue but unfortunately its not working with the theme,
please let me know, thanks!!March 21, 2017 at 12:22 pm #317872Will forward it to Ed so he can reply about it.
-RuiMarch 24, 2017 at 3:00 am #318363Hi @greattai
That plugin would not work with our theme. Do you have the latest theme + plugin updates?
– Ed
March 24, 2017 at 9:48 am #318376Hi Ed,
Yes, I am using the latest theme and plug-in.
Btw..the problem I want to fix is “chinese excerpt length”… its ok if you have other suggestion.
thanks!March 25, 2017 at 1:07 am #318469Please try this version of the theme – http://swiftideas.d.pr/8V4k/Ab6G3eWF
That should sort it for you!
– Ed
March 27, 2017 at 6:30 am #318521Hi Ed,
Thanks for your reply, but the problem seems still exist..
May I know what do you update on the new zip ?As I know.. the usual “word length” is count by space for english,
and chinese “word” without space.Is it possible to just give me a code to use on the child theme to count by words instead of space ?
And I also suggest to add a option on the “Excerpt Length” by “space(default)” and “character” later on.
thanks!*attached with the screen cap I use “15” as the Excerpt Length on your zip.
Attachments:
You must be logged in to view attached files.March 28, 2017 at 4:50 pm #318858Hi there,
You can try changing these 3 functions – https://www.dropbox.com/s/owp0xr30dri4p8j/Screenshot%202017-03-28%2016.44.01.png?dl=0
Let us know if any changes work for you, and we can integrate the “function_exists” check so they can be overridden in a child theme.
– Ed
April 26, 2017 at 9:55 am #322374Hi, sorry for so long.. what I did on these 3 functions on swift-framework/core/sf-formatting.php and its working fine for me now (to count characters instead of words):
function sf_excerpt( $limit ) {
global $post;
$excerpt = “”;
$custom_excerpt = sf_get_post_meta( $post->ID, ‘sf_custom_excerpt’, true );if ( $custom_excerpt != “” ) {
//edited by titus
//$excerpt = wp_trim_words( $custom_excerpt, $limit );
$excerpt = wp_html_excerpt( $custom_excerpt, $limit, ‘…’);
} else {
//edited by titus
//$excerpt = wp_trim_words( get_the_excerpt(), $limit );
$excerpt = wp_html_excerpt( get_the_excerpt(), $limit, ‘…’);
}
$excerpt = preg_replace( ‘\[[^\]]*\]
‘, ”, $excerpt );return ‘<p>’ . $excerpt . ‘</p>’;
}function sf_content( $limit ) {
$content = wp_trim_words( get_the_content(), $limit );
$content = preg_replace( ‘/\[.+\]/’, ”, $content );
$content = apply_filters( ‘the_content’, $content );
$content = str_replace( ‘]]>’, ‘]]>’, $content );return $content;
}function sf_custom_excerpt( $custom_content, $limit ) {
$locale = get_locale();
$content = ”;
/* edited by titus
if ( $locale == ‘zh_CN’ || $locale == ‘zh_SG’ || $locale == ‘zh_HK’ || $locale == ‘zh_TW’ ) {
$content = wp_trim_words( $custom_content, $limit );
} else {
$content = $custom_content; // This is needed to keep formatting
}*/
$content = wp_html_excerpt( $custom_content, $limit, ‘…’);
$content = preg_replace( ‘/\[.+\]/’, ”, $content );
$content = apply_filters( ‘the_content’, $content );
$content = str_replace( ‘]]>’, ‘]]>’, $content );return $content;
}April 26, 2017 at 12:20 pm #322393Great. Thanks for sharing your code.
-Rui
May 4, 2017 at 9:57 am #323293Hi Rui,
How can I put this on the child theme?
Its overwrited after theme update. please advise, thanks!May 4, 2017 at 3:24 pm #323375Hi,
When the next update is released you will be able to overwrite this via a child theme. Currently, this is not possible.
I have submitted a patch to enable this for the next release.
Thanks.
-
Posted in: Atelier
You must be logged in and have valid license to reply to this topic.