Last active
January 24, 2019 06:54
-
-
Save gatespace/1f1cd352b4aa130c4e1631bd4c3cc5d9 to your computer and use it in GitHub Desktop.
テキストを指定した文字数または行数でカットする ref: https://qiita.com/gatespace/items/08c3457cd7fcc232f131
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_excerpt_length( $length ) { | |
return 20; | |
} | |
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.trunk8 { | |
display: block; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#t8-default').trunk8(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p { | |
white-space: nowrap; | |
width: 100%; /* IE6 では width の指定が必要 */ | |
overflow: hidden; /* "overflow" の値は "visible" 以外のものを指定する */ | |
-o-text-overflow: ellipsis; /* Opera 9-10 */ | |
text-overflow: ellipsis; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$text = get_the_title(); // 元になる文字列 | |
$num_words = 40; // 単語数(WP Multibyte Patch 有効時は文字数) | |
$more = '…'; // カットした文字列の末尾につける文字列 | |
// HTMLエンティティを文字列に変換 | |
$text = html_entity_decode( $text ); | |
// 指定の文字数で切り出す | |
$text = wp_trim_words( $text, $num_words, $more ); | |
// HTMLエンティティを元に戻す | |
$text = htmlentities( $text ); | |
echo $text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$wpmp_conf['excerpt_mblength'] = 110; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment