トップページに特定カテゴリーの最新記事3件の全文を表示する方法

WEBデザイン

例えば、タイトルを「お知らせ」、カテゴリー「7」の記事を「3件」全文表示するには以下のようにTopページのファイル内に入力

<div id=”gorenraku”>
<h2>お知らせ</h2>
<div>
<?php query_posts(‘cat=7&showposts=3′);?>
<?php if (have_posts()) : ?>
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li>
<h3><?php the_time(get_option(‘date_format’)); ?></h3>
<?php the_content(); ?>
</li>
<?php endwhile; ?>
</ul>
<?php else : ?>
<p>現在お知らせ情報はありません。</p>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
タイトルとURLをコピーしました