カスタム投稿タイプを固定ページに表示させる方法
例:カスタム投稿タイプ「event」 表示件数3件
<?php
$args=array(
'post_type' => 'event', //カスタム投稿名
'posts_per_page'=> 3 //表示件数(-1で全ての記事を表示)
);
?>
<?php query_posts( $args ); ?>
<?php if(have_posts()): ?>
<?php while(have_posts()):the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: //記事が無い場合 ?>
記事が無い場合の処理
<?php endif; wp_reset_query(); //クエリのリセット ?>
単に改行させないだけなら以下
<?php remove_filter('the_content', 'wpautop'); ?>
<?php the_content(); ?>
コンテンツに文字制限を行う
例:200文字で制限し、それを超えると「…」を文末に付ける
<?php the_content(); ?>
この部分を以下に書き換える
<?php
if(mb_strlen($post->post_content,'UTF-8')>200){
$content= str_replace('\n', '', mb_substr(strip_tags($post-> post_content), 0, 200,'UTF-8'));
echo $content.'...';
}else{
echo str_replace('\n', '', strip_tags($post->post_content));
}
?>