给wordpress添加最新、热评、随机日志

首先把以下函数放在 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 .= ‘

  • ‘ . $post_title . ”.$$plusmsg.’
  • ‘;
    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 );
    ?>

    0 0 投票数
    文章评分
    订阅评论
    提醒
    guest

    4 评论
    最旧
    最新 最多投票
    内联反馈
    查看所有评论
    戈尔本
    2011年2月16日 13:47

    在哪改可以修改最新文章的条数,我的想显示出30条,设置了没效果

    qite
    2011年4月3日 18:26

    我的怎么出不来啊?弄上了没反应~~~

    4
    0
    希望看到您的想法,请您发表评论x