WordPressの抜粋表示(excerpt)を以下のように動作させたかったので、自作してみました。
	抜粋があれば抜粋表示
	moreタグがあれば、それに従う
	指定文字数より本文文字数が少なければ、そのまま表示
	指定文字数より本文文字数が多ければ抜粋表示
コード
functions.phpにコピペ。
[php]<?php
//WordPress抜粋表… 
  
        $categorysの配列を複数指定することで、複数のカテゴリから記事の一覧を取得することが可能です。
  
  
<?php
$categorys = array(27);
for ($i=0; $i<count($categorys); $i++) :
?>
<?php
query_posts('cat='.$categorys[$i]);
if (have_posts()) : while (have_posts()) : the_post();
?>
<h3 class="arrow"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<?php endwhile; ?>
<?php else: ?>
<p><?php echo esc_html(get_catname($categorys[$i]))."はまだありません。"; ?></p>
<?php endif; ?>
<?php endfor; ?>
パターン2
<?php if ( have_posts() ) : query_posts('cat=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>
<?php endif; ?>
カテゴリIDと表示数などを指定
<?php
$categorys = array(4,6,5);
for ($i=0; $i<count($categorys); $i++) :
?>
<h3><?php echo esc_html(get_catname($categorys[$i])); ?></h3>
<ul>
<?php
query_posts('showposts=5&cat='.$categorys[$i]);
if (have_posts()) : while (have_posts()) : the_post();
?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php else: ?>
<li><?php echo esc_html(get_catname($categorys[$i]))."はまだありません。"; ?></li>
</ul>
<?php endif; ?>
<?php endfor; ?>   graffiti on the web
      graffiti on the web      
この投稿へのコメント
コメントはまだありません。