Skip to content

Instantly share code, notes, and snippets.

@gatespace
Last active January 24, 2019 06:54
Show Gist options
  • Save gatespace/1f1cd352b4aa130c4e1631bd4c3cc5d9 to your computer and use it in GitHub Desktop.
Save gatespace/1f1cd352b4aa130c4e1631bd4c3cc5d9 to your computer and use it in GitHub Desktop.
テキストを指定した文字数または行数でカットする ref: https://qiita.com/gatespace/items/08c3457cd7fcc232f131
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
.trunk8 {
display: block;
}
var trunk8 = $('.trunk8');
var lines = 2;
if( trunk8.length > 0 ){
trunk8.each(function(){
if( $(this).attr("data-line") ){
lines = $(this).attr("data-line");
} else {
lines = 2;
}
$(this).trunk8({
lines: lines
});
});
}
$('#t8-default').trunk8();
p {
white-space: nowrap;
width: 100%; /* IE6 では width の指定が必要 */
overflow: hidden; /* "overflow" の値は "visible" 以外のものを指定する */
-o-text-overflow: ellipsis; /* Opera 9-10 */
text-overflow: ellipsis;
}
<?php
$text = get_the_title(); // 元になる文字列
$num_words = 40; // 単語数(WP Multibyte Patch 有効時は文字数)
$more = '&hellip;'; // カットした文字列の末尾につける文字列
// HTMLエンティティを文字列に変換
$text = html_entity_decode( $text );
// 指定の文字数で切り出す
$text = wp_trim_words( $text, $num_words, $more );
// HTMLエンティティを元に戻す
$text = htmlentities( $text );
echo $text;
$wpmp_conf['excerpt_mblength'] = 110;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment