これはWordPress / PHPの質問です(非常に初心者だと思います)。次のコードを使用して、最新のブログ投稿へのリンクを挿入し、その後に投稿日を挿入しようとしています。
<div class="latest_post">
<ul><li><span class="recent_blog">LATEST POST</span><?php
$args = array(
'numberposts' => 1,
'category' => 71,
'post_status' => 'publish',
);
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ) {
echo '<a href="' . get_permalink($recent["ID"]) . '"> <strong>' . $recent["post_title"].'</strong></a>';
}
wp_reset_query();
?> (<?php echo get_the_date('Y/m/d'); ?>)</li></ul>
</div><!-- .latest_post -->
しかし、<?php echo get_the_date('Y/m/d'); ?>
どこから来たのかわからない間違った日付「(2015/04/23)」を返します。(2017/01/02)のはずです。誰かが私がそれがどこでうまくいかなかったかを見つけるのを手伝ってもらえますか?または、正しい日付を取得する他の方法はありますか?
前もって感謝します!
実際には参照に基づいています:-https://developer.wordpress.org/reference/functions/get_the_date/
(投稿が書かれた日付を取得します。)
したがって、この関数に投稿IDを指定して、特定の投稿日を取得します
または
現在の日付が必要な場合は、次を使用できます:-
<?php echo date('Y/m/d');?>
私はあなたが以下のようにしなければならないと思います:-
foreach( $recent_posts as $recent ) {
echo '<a href="' . get_permalink($recent["ID"]) . '"> <strong>' . $recent["post_title"].'</strong></a>';
echo get_the_date('Y/m/d',$recent["ID"]);
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加