特定のページ(トップページではないページ)に、get_posts()を用いて特定のカテゴリーの記事一覧(タイトル)を表示したいと思っています。
<?php
$posts = get_posts('numberposts=5&category=14');
foreach($lastposts as $post) :
setup_postdata($post);
?>
<li><span class="date"><?php the_time('Y/m/d') ?></span> <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
カテゴリーID:14の記事一覧を表示したいとして、このようなコードを考えたのですが、うまくいきません。
このforumの過去記事を検索して、
<?php
$posts = get_posts('numberposts=0&category=14');
global $post;
?>
<?php
if($posts): foreach($posts as $post): setup_postdata($post); ?>
<li><span class="date"><?php the_time('Y/m/d') ?></span> <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; endif;
?>
というコードも作成してみたのですが、やはりうまくいきません。
結果はどうなるかというと、最新のページ(投稿ではなく)が1件のみ出力されます。
試しにカテゴリー指定を消してみましたが、結果は同じです。
ちなみに、トップページに
<?php
$lastposts = get_posts('numberposts=5');
foreach($lastposts as $post) :
setup_postdata($post);
?>
<li><span class="date"><?php the_time('Y/m/d') ?></span> <a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
というコードが書いてあって、こちらは正しい結果が出力されています。
どこをどう修正すればよいのかご教示いただければ幸いです。