HOME > WordPress > カスタムフィールドの文字数を制限して出力する

カスタムフィールドの文字数を制限して出力する

カスタムフィールドだけで構成しているカテゴリーがあるとして、そのカテゴリーの記事一覧をトップページに表示するときに使った方法です。

フィールドの文章すべてではなく、指定した文字数だけに制限して出力します。

<?php
			if(mb_strlen(get_field('フィールドname'))>60) { $hoge= mb_substr(get_field('フィールドname'),0,59) ; echo $hoge. … ;}
			else {echo get_field('フィールドname');}
			?>
参考サイト

    Warning: Undefined array key "HTTP_REFERER" in /home/xs241045/ridesign.jp/public_html/lib/wp/wp-content/themes/libridesign2017/single-post.php on line 54

Warning: Undefined array key "HTTP_REFERER" in /home/xs241045/ridesign.jp/public_html/lib/wp/wp-content/themes/ridesignjp2016/relatedLinks.php on line 10