Ich verwende ein Plugin, das die Bewertung von Kommentaren für WordPress ermöglicht, und ich möchte in der Lage sein, 4 Links für den Beitrag zu haben.
- neuster Kommentar
- ältester Kommentar
- am besten bewertet
- am niedrigsten bewertet
wodurch sich die Reihenfolge der Kommentare entsprechend ändert.
Ich weiß, dass die Links so etwas lesen sollten
- 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
Die Sache ist, wenn es um PHP geht, bin ich ein absoluter Neuling, also habe ich mich gefragt, was ich hier ändern/hinzufügen muss;
<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>
damit das obige funktioniert? Oder muss ich hier etwas ändern;
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;
}
Danke
Ich sehe in dem von Ihnen geposteten Code nichts, was mit dem Erstellen von Links zu tun hat. aber andererseits habe ich auch keine ahnung von wordpress
– Petros Mastrantonas
23. Mai 2013 um 16:04 Uhr