特定カテゴリーの記事のタイトルを表示
<?php while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>" class="archive"> <p> <time datetime="<?php the_time('Y-m-d')?>"><?php the_time("Y/n/j"); ?></time> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a> </p> </article> <?php endwhile; ?>
特定のカテゴリーの記事を取り出すには、sql でフィルターをかければいい。
<?php query_posts('showposts=3&cat=1'); while (have_posts()) : the_post(); ?> <article id="post-<?php the_ID(); ?>" class="archive"> <p> <time datetime="<?php the_time('Y-m-d')?>"><?php the_time("Y/n/j"); ?></time> <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <span><?php the_title(); ?></span> </a> </p> </article> <?php endwhile; ?>上記の query_posts(‘showposts=3&cat=1’); が味噌。
showposts は、表示件数。
cat は、ターゲットのカテゴリーコード。
スポンサーリンク