ひゅーまにあ:shortcodesプラグインphp追加(文字数が多い場合)

shortcodes-ultimate/templates/list-loop.php の編集

<!–?php //the_title(); ?–> の部分を下記に編集。
長すぎるタイトルを文字数で区切る。
さらに、モバイル時とPC時で、文字数を変更(モバイル時18文字、PC時30文字)

【注意】
shortcodes unimate プラグインをバージョンアップ時に、下記表記が維持されているか確認。
(サイト上での表示は、php命令文が正しく表示できないため、設計で確認すること!
——

<ul class="su-posts su-posts-list-loop">
<?php
// Posts are found
if ( $posts->have_posts() ) {
	while ( $posts->have_posts() ) {
		$posts->the_post();
		global $post;
?>
<?php if ( wp_is_mobile() ) : ?>
<li id="su-post-<?php the_ID(); ?>" class="su-post"><a href="<?php the_permalink(); ?>">
	<?php if (mb_strlen($post->post_title) > 18) {
	echo mb_substr(the_title($before = '', $after = '', FALSE), 0, 18)  . '...'; }  else {
		the_title();
	} ?> 
</a></li>
<?php else: ?>
<li id="su-post-<?php the_ID(); ?>" class="su-post"><a href="<?php the_permalink(); ?>">
	<?php if (mb_strlen($post->post_title) > 30) {
	echo mb_substr(the_title($before = '', $after = '', FALSE), 0, 30) .  '...'; } else {
		the_title();
	} ?> 
</a></li>
<?php endif; ?>

<?php
	}
}
// Posts not found
else {
?>
<li><?php _e( 'Posts not found', 'shortcodes-ultimate' ) ?></li>
<?php
}
?>
</ul>

元々のファイル内容は以下の通り

<ul class="su-posts su-posts-list-loop">
<?php
// Posts are found
if ( $posts->have_posts() ) {
	while ( $posts->have_posts() ) {
		$posts->the_post();
		global $post;
?>
<li id="su-post-<?php the_ID(); ?>" class="su-post"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
	}
}
// Posts not found
else {
?>
<li><?php _e( 'Posts not found', 'shortcodes-ultimate' ) ?></li>
<?php
}
?>
</ul>

 

9行目の the_title()  の部分から分岐させた。
モバイルか否かの分岐 モバイルなら18文字以降を省略し  …  で表示。
PCの場合は30文字以降を省略し  …  で表示。