首先把以下函数放在 WordPress 主题文件夹里的 functions.php 中:
function filter_where($where = ”) {
$where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘-30 days’)) . “‘”;
return $where;
}
function some_posts($orderby = ”, $plusmsg = ”,$limit = 10) {
add_filter(‘posts_where’, ‘filter_where’);
$some_posts = query_posts(‘posts_per_page=’.$limit.’&caller_get_posts=1&orderby=’.$orderby);
foreach ($some_posts as $some_post) {
$output = ”;
$post_date = mysql2date(‘y年m月d日’, $some_post->post_date);
$commentcount = ‘(‘.$some_post->comment_count.’ 条评论)’;
$post_title = htmlspecialchars(stripslashes($some_post->post_title));
$permalink = get_permalink($some_post->ID);
$output .= ‘
‘;
echo $output;
}
wp_reset_query();
}
可以看到第二行中的 30 就是指最近 30 天,也可以根据你自己的需要修改这个时间。至于调用则和升级版之前的一样,下面只是比上次多加了一个 $limit 参数:
< ?php
//最新日志
some_posts( $orderby = ‘date’, $plusmsg = ‘post_date’, 10 );
//热评日志
some_posts( $orderby = ‘comment_count’, $plusmsg = ‘commentcount’, 10 );
//随机日志
some_posts( $orderby = ‘rand’, $plusmsg = ‘post_date’, 10 );
?>
发表回复