WordPressテーマ作成~記事ページに載せるもの追加(タイトル・投稿日・更新日・本文・前後記事へのリンク)~
投稿日
更新日
記事のページはを下の画像みたいな感じにしたいと思っているので、
今回は、記事のページに、タイトル・投稿日・更新日・本文・前後記事へのリンクを表示させていく内容です。
ヘッダー・フッターとか、左側のメニュー部分は前ページ同じように出力してるので、赤枠内の部分を作っていきます。
記事ページに使うファイル名は、「single.php」です。
まずは他のページ同様のヘッダーやフッター部分を書いていきます。
1 2 3 4 5 6 7 |
<?php get_header(); //ここに記事ページの赤枠の内容を書いていく get_footer(); |
※画像にはコメント部分もあるけど、今回はそれ以外を表示していきます。
記事ページの内容を出すための内容は以下。
1 2 3 4 5 6 7 8 9 10 11 12 |
if ( have_posts() ) : ?> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php the_title( '<h1>', '</h1>' ); ?> 投稿日<time><?php the_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); ?></time> 更新日<time><?php the_modified_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); ?></time> <p><?php the_author(); ?></p> <?php the_content(); ?> </article> <?php endif; previous_post_link(); next_post_link(); |
ちなみに内訳は下記の通り
1 2 3 4 5 |
タイトル・・・<?php the_title( '<h1>', '</h1>' ); ?> 投稿日・・・・<time><?php the_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); ?></time> 更新日・・・・<time><?php the_modified_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); ?></time> 投稿者・・・・<p><?php the_author(); ?></p> 本文・・・・・<?php the_content(); ?> |
実際に出力される状態になったら、あとはCSSで表示を整えていきましょー。
(まだ調整しきれてないけど本文を上手く表示させるの大変そうかも…)