Sherry
#1
こんにちは。
お世話になります。
Sherryと申します。
ブログ記事に、作成日と更新日を出力して表示させることは出来ますか?
固定ページでしたら、関数からレイアウトファイルまたは、コード欄に
<small>作成日:<?php echo $this->BcBaser->getContentCreatedDate('Y-m-d', $data['Content']['created_date']) ?> 更新日:<?php echo $this->BcBaser->getContentModifiedDate('Y-m-d', $data['Content']['modified_date']) ?></small>
こんな感じで出力が出来るのですが、関数リファレンスを見ると「 Blog getPostDate」しか無いようです ><;
作成日=更新日となってしまいます。
過去の投稿を更新して最新の情報として公開したいものの、
更新日のみになってしまうので、下記画像のように作成日を残しておきたいのです。
例:固定ページの表示テスト

宜しくお願いいたします。
seto
#2
こんにちは
ブログ記事の作成日と更新日を出力する関数は見つからなかったので、post配列から直接出力すると表示できました。
作成: <?php echo date('Y-m-d', strtotime($post['BlogPost']['created'])) ?><br>
更新: <?php echo date('Y-m-d', strtotime($post['BlogPost']['modified'])) ?><br>
投稿: <?php $this->Blog->postDate($post) ?>
「いいね!」 5
Sherry
#3
seto さま
ご返信ありがとうございます!
提示して頂いたコードで正しく表示できました。
同時にメタ出力にも使えてとても助かりました。
<meta property="article:published_time" content="<?php $this->Blog->postDate( $post, 'Y-m-d' ); ?>T<?php $this->Blog->postDate( $post, 'H:i:s'); ?>Z" />
<meta property="article:modified_time" content="<?php echo date('Y-m-d', strtotime($post['BlogPost']['modified'])) ?>T<?php echo date('H:i:s', strtotime($post['BlogPost']['modified'])) ?>Z" />
<meta property="og:updated_time" content="<?php echo date('Y-m-d', strtotime($post['BlogPost']['modified'])) ?>T<?php echo date('H:i:s', strtotime($post['BlogPost']['modified'])) ?>Z" />
出力結果
<meta property="article:published_time" content="2019-04-20T06:30:00Z" />
<meta property="article:modified_time" content="2019-04-24T07:02:24Z" />
<meta property="og:updated_time" content="2019-04-24T07:02:24Z" />
上記はブログ記事用です。
誠にありがとうございました!
「いいね!」 1