Joe*_*oey 2 php wordpress echo
这是一个Word Press/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 -->
Run Code Online (Sandbox Code Playgroud)
但是,<?php echo get_the_date('Y/m/d'); ?>返回错误的日期"(2015/04/23)",我不知道它来自哪里.它应该是(2017/01/02).谁能帮我找出它出错的地方?或者,任何其他方式来获取正确的日期?
先感谢您!
实际上基于参考: - https://developer.wordpress.org/reference/functions/get_the_date/
(它检索撰写帖子的日期.)
因此要么在此函数中提供post id以获取特定的Post日期
要么
如果您想要当前日期,那么您可以使用: -
<?php echo date('Y/m/d');?>
Run Code Online (Sandbox Code Playgroud)
我想你必须这样做: -
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"]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6853 次 |
| 最近记录: |