我正在使用一个插件,可以对 wordpress 进行评论评级,我希望能够在帖子上有 4 个链接;
- 最新评论
- 最旧的评论
- 收视率最高
- 最低评价
这将相应地改变评论的顺序。
我知道链接应该是这样的
- www.example.com?orderby=comment_date&order=ASC
- www.example.com?orderby=comment_date&order=DESC
- www.example.com?orderby=comment_rating&order=ASC
- www.example.com?orderby=comment_rating&order=DESC
问题是,当谈到 php 时,我是一个完全的新手,所以我想知道我必须在这里更改/添加什么;
<ol class="commentlist">
<?php if (function_exists(ckrating_get_comments))
{$post_id = $post->ID;$mycomments=ckrating_get_comments("post_id=$post_id&status=approve&orderby=comment_date&order=ASC");}
else$mycomments = null;wp_list_comments(array(), $mycomments);?>
</ol>
为了使上述工作?或者我需要在这里改变一些东西吗?
function ckrating_get_comments( $args = '' ) {
global $wpdb;
$defaults = array('status' => '', 'orderby' => 'comment_date', 'order' => 'DESC', 'number' => '', 'offset' => '', 'post_id' => 0);
$args = wp_parse_args( $args, $defaults );
extract( $args, EXTR_SKIP );
// $args can be whatever, only use the args defined in defaults to compute the key
$key = md5( serialize( compact(array_keys($defaults)) ) );
$last_changed = wp_cache_get('last_changed', 'comment');
if ( !$last_changed ) {
$last_changed = time();
wp_cache_set('last_changed', $last_changed, 'comment');
}
$cache_key = "get_comments:$key:$last_changed";
if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) {
return $cache;
}
$post_id = absint($post_id);
if ( 'hold' == $status )
$approved = "comment_approved = '0'";
elseif ( 'approve' == $status )
$approved = "comment_approved = '1'";
elseif ( 'spam' == $status )
$approved = "comment_approved = 'spam'";
else
$approved = "( comment_approved = '0' OR comment_approved = '1' )";
$order = ( 'ASC' == $order ) ? 'ASC' : 'DESC';
$orderby = (isset($orderby)) ? $orderby : 'comment_rating';
$number = absint($number);
$offset = absint($offset);
if ( !empty($number) ) {
if ( $offset )
$number = 'LIMIT ' . $offset . ',' . $number;
else
$number = 'LIMIT ' . $number;
} else {
$number = '';
}
if ( ! empty($post_id) )
$post_where = $wpdb->prepare( 'comment_post_ID = %d AND', $post_id );
else
$post_where = '';
$comments = $wpdb->get_results( "SELECT * FROM $wpdb->comments WHERE $post_where $approved ORDER BY $orderby $order $number" );
wp_cache_add( $cache_key, $comments, 'comment' );
return $comments;
}
谢谢