エントリーのタイトルがやたらと長くなって、妙なところで折り返されてしまうのが気になります。
そこで、カスタマイズしてみます。
以下のスクリプトを適当な名前で保存します。
例「trim.pl」
use MT::Template::Context;
use MT::ConfigMgr;
use Encode qw/ from_to /;MT::Template::Context->add_global_filter(trimj_to => sub {
my($str, $nstr, $ctx) = @_;
my $sippo = '...';my $tmpstr = $str;
my $c = MT::ConfigMgr->instance->PublishCharset;
my $conv_in;
if (lc $c eq lc 'Shift_JIS') {
$conv_in = 'shiftjis';
} elsif (lc $c eq lc 'ISO-2022-JP') {
$conv_in = 'iso-2022-jp';
} elsif (lc $c eq lc 'UTF-8') {
$conv_in = 'utf8';
} elsif (lc $c eq lc 'EUC-JP') {
$conv_in = 'euc-jp';
}
if ($conv_in ne 'euc-jp') {
from_to($str, $conv_in, 'euc-jp');
}# 比較
my $lenstr = length($str);
if($lenstr <= $nstr) {
return $tmpstr;
}my $out = substr($str,0,$nstr);
if ($out =~ /\x8F$/ or $out =~ tr/\x8E\xA1-\xFE// % 2) {
chop $out;
if($out =~ /\x8F$/){
chop $out;
}
}
$out .= $sippo; # 尻尾を付けたくない場合は、コメントアウトのこと。if ($conv_in ne 'euc-jp') {
from_to($out, 'euc-jp', $conv_in);
}return $out;
});1;
保存したファイルを「plugins」にアップロードしてパーミッションを「755」もしくは「705」にします。
あとはトリミングしたいタグの中で、「trimj_to="20"」というのを挿入します。
例えば、
<$MTEntryTitle trimj_to="20"$>
こんな感じ。
数字部分は自由に変更します。
う〜ん♪すっきりぃ〜♥
参考サイト
MT 長いタイトルをトリミングする[ M's folderさま ]
日本語対応トリミングフィルタ[ 人生迷い箸さま ]
