カスタムフィールド値の文字数を制限して表示
<?php echo post_custom('abc'); ?>
かたつむりくんのWWW様の
WordPressのカスタムフィールドで最初のn文字だけを表示して、残りを…にする方法は? | かたつむりくんのWWWより
<?php
$pattern = '/(^.{50})(.+)/u';
$subject = post_custom('abc');
$matches = array();
preg_match($pattern, $subject , $matches);
if ($matches[2] != '') {
$out = $matches[1] . '...';
} else {
$out = $subject;
}
echo($out);
?>