显示包含日期的最近修改过的页面列表

时间:2013-05-16 16:50:26

标签: php wordpress

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

<?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所以请原谅我的无知;)

2 个答案:

答案 0 :(得分: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; ?>

答案 1 :(得分:1)

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

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

然后你可以像任何其他领域一样检索它:

$post->post_modified_gmt

如果你想格式化它,你可以使用php DateTime类或MySQL's date formatting options