我有一个代码显示最近3次更新的页面或帖子。
当我将此代码添加到主题提要栏时,它工作得非常好。php文件。
<?php
$today = current_time(\'mysql\', 1);
$count = 3;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb-
>posts WHERE post_status = \'publish\' AND (post_type = \'page\' OR post_type =
\'post\') AND post_modified_gmt < \'$today\' ORDER BY post_modified_gmt DESC
LIMIT $count")):
?>
<h4><?php _e("Recent Updates"); ?></h4>
<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; ?>
但当我在主题函数上添加此代码时。php文件,并使用woody片段php代码在小部件中调用它。然后,它只显示当前页面作为最近更新的页面3次。以下是功能代码:
function iq_recent_update(){
global $wpdb;
$today = current_time(\'mysql\', 1);
$count = 3;
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb-
>posts WHERE post_status = \'publish\' AND (post_type = \'page\' OR post_type =
\'post\') AND post_modified_gmt < \'$today\' ORDER BY post_modified_gmt DESC
LIMIT $count")):
?>
<h4><?php _e("Recent Updates"); ?></h4>
<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;
}
在woody php代码片段中,我将其称为
<?php iq_recent_update(); ?>
它只显示当前页面名称。为什么工作方式不同?我如何解决?
非常感谢。