Home >Backend Development >PHP Tutorial >wordpress实现热评文章(一定时间内,指定目录)

wordpress实现热评文章(一定时间内,指定目录)

WBOY
WBOYOriginal
2016-06-06 20:48:38888browse

想实现一个wordpress的热评文章(一定时间内,指定目录)功能,不想用插件,从网上找了很久,终于实现了2/3,为什么这么说,因为根据评论量排序和一定时间内这两个都实现了,但是指定目录这个还没实现。

代码贴上,这段代码写在wp模板的function.php内。

<code>function popularposts_with_comment($posts_num=10,$days=7,$display=ture) {
global $wpdb,$post; 
$output = '';      
$most_comment = $wpdb->get_results("
    SELECT ID , post_title , comment_count 
    FROM $wpdb->posts 
    WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) 
                    <a class="applist-img" href="'.get_permalink().'">'.get_the_post_thumbnail().'</a>'.
                    '<div class="app-des">
                    <h6><a href="'.get_permalink().'">'.$post_title. '
                    </a></h6>
                    <p>浏览次数:'.getPostViews(get_the_ID()).'
                    </p>
</div>';
    }
    echo $output;
</code>

}

回复内容:

想实现一个wordpress的热评文章(一定时间内,指定目录)功能,不想用插件,从网上找了很久,终于实现了2/3,为什么这么说,因为根据评论量排序和一定时间内这两个都实现了,但是指定目录这个还没实现。

代码贴上,这段代码写在wp模板的function.php内。

<code>function popularposts_with_comment($posts_num=10,$days=7,$display=ture) {
global $wpdb,$post; 
$output = '';      
$most_comment = $wpdb->get_results("
    SELECT ID , post_title , comment_count 
    FROM $wpdb->posts 
    WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) 
                    <a class="applist-img" href="'.get_permalink().'">'.get_the_post_thumbnail().'</a>'.
                    '<div class="app-des">
                    <h6><a href="'.get_permalink().'">'.$post_title. '
                    </a></h6>
                    <p>浏览次数:'.getPostViews(get_the_ID()).'
                    </p>
</div>';
    }
    echo $output;
</code>

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn