現在、この状態。
ここから置き換えが必要なところを書き換えていく。
<?php get_header(); ?> <div id="main"> <div id="content"> <div class="content_container"> <h2 class="content_title">content_title</h2> <div class="content_category">content_category</div> <div class="content_tag">content_tag</div> <div class="content_author">content_author</div> <div class="content_create_datetime">0000/00/00 00:00:00</div> <div class="content_updator">content_updator</div> <div class="content_update_datetime">0000/00/00 00:00:00</div> <div class="content_parts"> CONTENT の 中身 1 </div> </div> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?>
- 変更点01:記事の中身を表示するためのループ
<div class="content_container"> ・・・ </div>
この中身が表示記事数分だけループする。whileで回すのが吉らしい。
<?php while (have_posts()) : the_post(); ?> <?php endwhile; ?>
have_postsで表示する投稿が残っているか判断し
the_postで次の投稿に進み、グローバル変数$postを設定するとのこと。
詳細は関数リファレンス/WP Query – WordPress Codex 日本語版に。 - 変更点02:記事の中身
前述のthe_postで、記事ごとの情報を$postに割り当てているので、その中身を引っ張り出せるように書き換えていく。<h2 class="content_title">content_title</h2> <div class="content_category">content_category</div> <div class="content_tag">content_tag</div> <div class="content_author">content_author</div> <div class="content_create_datetime">0000/00/00 00:00:00</div> <div class="content_updator">content_updator</div> <div class="content_update_datetime">0000/00/00 00:00:00</div> <div class="content_parts"> CONTENT の 中身 1 </div>
それぞれに使用するテンプレートタグは以下のとおり。
テンプレートタグのリストはこちら。
タイトル → the_title
該当ページURL → the_permalink
カテゴリー → the_category
タグ → the_tags
投稿者 → the_author
公開日時 → the_dateとthe_time
※the_dateは「同じ日に複数の記事がある場合は、最初の記事とともに一度だけ出力される。」ということなので、the_timeに “Y/m/d H:i:s” を出力させた方がイイ。
更新者 → the modified author
更新日時 → the_modified_dateとthe_modified_time
本文 → the_content<h2 class="content_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="content_category"><?php the_category(', ') ?></div> <div class="content_tag"><?php the_tags(); ?></div> <div class="content_author"><?php the_author(); ?></div> <div class="content_create_datetime"><?php the_time('Y/m/d H:i:s'); ?></div> <div class="content_updator"><?php the_modified_author(); ?></div> <div class="content_update_datetime"><?php the_modified_date('Y/m/d'); ?> <?php the_modified_time('H:i:s'); ?></div> <div class="content_parts"> <?php the_content('more...', 'false'); ?> </div>
ここまでやるとこうなる。
<?php get_header(); ?> <div id="main"> <div id="content"> <div class="content_container"> <?php while (have_posts()) : the_post(); ?> <h2 class="content_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="content_category"><?php the_category(', ') ?></div> <div class="content_tag"><?php the_tags(); ?></div> <div class="content_author"><?php the_author(); ?></div> <div class="content_create_datetime"><?php the_time('Y/m/d H:i:s'); ?></div> <div class="content_updator"><?php the_modified_author(); ?></div> <div class="content_update_datetime"><?php the_modified_date('Y/m/d'); ?> <?php the_modified_time('H:i:s'); ?></div> <div class="content_parts"> <?php the_content('more...', 'false'); ?> </div> <?php endwhile; ?> </div> </div> <?php get_sidebar(); ?> </div> <?php get_footer(); ?>
ふむ。いいかな。