0

我正在使用以下效果很好:

<?php
$today = current_time('mysql', 1);
$howMany = 10;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<ul>
<?php
foreach ($recentposts as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li><a href='".get_permalink($post->ID)."'>";
the_title();
echo '</a></li>';
}
?>
</ul>
<?php endif; ?>

但需要知道如何在结束</li>标记处添加修改日期。我使用此页面http://bit.ly/13zkdP8尝试了几种方法,但似乎无法使其正常工作。另外,我看到了这个类似的问题:http ://bit.ly/13zkEsP但我想显示页面而不是帖子。我正在学习 PHP,所以请原谅我的无知 ;)

4

2 回答 2

1

您需要从数据库中获取该信息,然后相应地显示它:

<?php 
$today = current_time('mysql', 1);
$howMany = 10;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title, post_modified_gmt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'page' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<ul>
<?php
foreach ($recentposts as $post) {
    if ($post->post_title == '') 
        $post->post_title = sprintf(__('Post #%s'), $post->ID);
    echo "<li><a href='".get_permalink($post->ID)."'>";
    the_title();
    echo '</a> ' . mysql2date('d/m/Y', $post->post_modified_gmt) .'</li>';
}
?>
</ul>
<?php endif; ?>
于 2013-05-16T16:55:10.093 回答
1

将该字段添加post_modified_gmt到您的选择列表中:

$wpdb->get_results("SELECT ID, post_title, post_modified_gmt FROM...

然后您可以像检索任何其他字段一样检索它:

$post->post_modified_gmt

如果要格式化,可以使用 php DateTime类或MySQL 的日期格式化选项

于 2013-05-16T16:56:26.043 回答