やりたいこと
Modern ThemesのPortfolioに同梱のwork記事一覧と記事のテンプレートは、そのままだと投稿日が表示されない。
なるべく複雑なことをせずに投稿日が表示されるようにしたい。
手順
テンプレートファイルにコードを追加する。
work記事一覧
Portfolio: content-works.phpのタイトル表示処理の上にコードを追加する。
<?php echo get_the_date(); ?> <h4><?php the_title(); ?></h4>
全体としては以下になる。
<?php
/**
* The template used for displaying page content in page-works.php
*
* @package portfolio
*/
?>
<div class="col-1-3">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="entry-content">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('small-square'); ?></a>
<hr class="line" />
<?php echo get_the_date(); ?>
<h4><?php the_title(); ?></h4>
<p class="works-meta"> <?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list( __( ', ', 'portfolio' ) );
/* translators: used between list items, there is a space after the comma */
$tag_list = get_the_tag_list( '', __( ', ', 'portfolio' ) );
if ( ! portfolio_categorized_blog() ) {
// This blog only has 1 category so we just need to worry about tags in the meta text
if ( '' != $tag_list ) {
$meta_text = __( '%2$s', 'portfolio' );
} else {
$meta_text = __( '', 'portfolio' );
}
} else {
// But this blog has loads of categories so we should probably display them here
if ( '' != $tag_list ) {
$meta_text = __( '%1$s %2$s', 'portfolio' );
} else {
$meta_text = __( '%1$s', 'portfolio' );
}
} // end check for categories on this blog
printf(
$meta_text,
$category_list,
$tag_list,
get_permalink()
);
?>
</p><!-- .works-meta -->
</div><!-- .entry-content -->
</article><!-- #post-## -->
</div><!-- col-1-3 -->
get_the_date()
記事の日付を出力するメソッド。
同じページ内で実行するとその都度日付を出力する。
記事
Portfolio: single-work.phpのタイトル表示処理の上にコードを追加する。
<div class="col-1-1">
<?php the_date(); ?>
<?php the_title( '<h1 class="entry-title">', '</h1>' );
ヘッダー部分の処理は以下になる。
<header class="entry-header single-work-header">
<div class="grid grid-pad">
<div class="col-1-1">
<?php the_date(); ?>
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
<div class="entry-meta">
<?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list( __( ', ', 'portfolio' ) );
/* translators: used between list items, there is a space after the comma */
$tag_list = get_the_tag_list( '', __( ', ', 'portfolio' ) );
if ( ! portfolio_categorized_blog() ) {
// This blog only has 1 category so we just need to worry about tags in the meta text
if ( '' != $tag_list ) {
$meta_text = __( '%2$s', 'portfolio' );
} else {
$meta_text = __( '', 'portfolio' );
}
} else {
// But this blog has loads of categories so we should probably display them here
if ( '' != $tag_list ) {
$meta_text = __( '%1$s %2$s', 'portfolio' );
} else {
$meta_text = __( '%1$s', 'portfolio' );
}
} // end check for categories on this blog
printf(
$meta_text,
$category_list,
$tag_list,
get_permalink()
);
?>
</div><!-- .entry-meta -->
</div><!-- .col-1-1 -->
</div><!-- .grid -->
</header><!-- .entry-header -->
the_date()
日付を出力するメソッド。
同じページ内で複数回呼び出された場合、初回のみ日付を出力する。

