BLOG
[WordPress]固定ページで投稿一覧表示方法
2015/5/9
WordPressで固定ページを新規で作成して、ページのテンプレートをオリジナルで作ったlist.phpに変更しました。
しかし投稿が表示されません。while(have_posts())のループのみだとうまくいかず、query_post()というテンプレートタグを使用して解決しました。
list.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php /* Template Name: list */ ?> <?php get_header(); ?> <div id="wrapper"> <div id="content"> <h1>BLOG</h1> <?php query_posts('post_type=post&paged='.$paged); ?> <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p class="small"><?php echo get_the_date(); ?></p> <?php the_excerpt(); ?> <p class="tx_right block_b"><a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>">詳細...</a></p> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> </div> <!-- /#content --> <?php get_sidebar(); ?> </div> <!-- /#wrapper --> <?php get_footer(); ?> |
下記を追加しています。
1 |
<?php query_posts('post_type=post&paged='.$paged); ?> |
1 |
<?php wp_reset_query(); ?> |
Tag:WordPress