WordPressで記事一覧を表示する方法

<?php
/*
Plugin Name: Custom Posts Per Page
Version: 1.0
Plugin URI: http://wordpress.org/support/6/11211
Description: Change the number of posts per page displayed for different page types.
Author: Based on code by rboren & brehaut
Author URI:
*/
$posts_per['home']      = 4;
$posts_per['day']       = 10;
$posts_per['month']     = 10;
$posts_per['search']    = 10;
$posts_per['year']      = 999;
$posts_per['author']    = 999;
$posts_per['category']  = 999;

function custom_posts_per_page($query_string) {
global $posts_per;

 $query = new WP_Query();
 $query->parse_query($query_string);
 
 if ($query->is_home) {
  $num = $posts_per['home'];
 
 } elseif ($query->is_day) {
  $num = $posts_per['day'].'&order=ASC';
 
 } elseif ($query->is_month) {
  $num = $posts_per['month'].'&order=ASC';
 
 } elseif ($query->is_year) {
  $num = $posts_per['year'].'&order=ASC';
 
 } elseif ($query->is_author) {
  $num = $posts_per['author'];
 
 } elseif ($query->is_category) {
  $num = $posts_per['category'];
 
 } elseif ($query->is_search) {
  $num = $posts_per['search'];
 }
 
 if (isset($num)) {
 
 
  if (preg_match("/posts_per_page=/", $query_string)) {
   
   $query_string = preg_replace("/posts_per_page=[0-9]*/", "posts_per_page=$num", $query_string);
  } else {
   if ($query_string != '') {
    $query_string .= '&';
   }
  $query_string .= "posts_per_page=$num";
  }
  
 }
 
return $query_string;
}
add_filter('query_string', 'custom_posts_per_page');
?>
上記をコピー(またはここからダウンロード)してperpage.php名前を付けて保存します。これをプラグインのディレクトリにアップロードして、プラグインを有効にします。

「home」がトップページに表示する記事数、categoryがカテゴリページに表示する記事数です。今回のこのperpage.phpというプラグインは、テンプレート毎に表示する記事数を変更できるというもので、これをしないと例えばトップページで「5」記事表示にしてると、カテゴリページでも「5」記事しか表示されない、という風になるようです。
$posts_per['home'] = 10;
$posts_per['day'] = 10;
$posts_per['month'] = 999;
$posts_per['search'] = 10;
$posts_per['year'] = 999;
$posts_per['author'] = 999;
$posts_per['category'] = 999;
category.phpの本文エリアを以下のように編集。

<ul><?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>
<li id=”catpost-<?php the_ID(); ?>”>
<a href=”<?php the_permalink() ?>” rel=”bookmark”
title=”Permanent Link: <?php the_title(); ?>”> <?php the_title(); ?></a></li>

<?php endforeach; else: ?> </ul>

<p>
<?php _e(’Sorry, no posts matched your criteria.’); ?></p>

<?php endif; ?>
【参考にした記事】
wordpressのカテゴリで記事タイトルをリスト表示させる方法
スポンサーリンク