Замена плагина «Лучшие комментаторы»

Замена плагина «Последние комментарии»

Открываем файл шаблона functions.php и вставляем в него следующий код:

function get_recent_comments( $args ) {
	global $wpdb, $comments, $comment;
	extract( $args, EXTR_SKIP );
	$options = get_option( 'widget_recent_comments' );
	$title   = empty( $options['title'] ) ? __( '<h3>Свежие комментарии</h3>' ) :
		apply_filters( 'widget_title', $options['title'] );
	if ( ! $number = (int) $options['number'] ) {
		$number = 5;
	} else if ( $number < 1 ) {
		$number = 1;
	} else if ( $number > 10 ) {
		$number = 10;
	}
	if ( ! $comments = wp_cache_get( 'recent_comments', 'widget' ) ) {
		$comments = $wpdb->get_results( "SELECT*FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT $number" );
		wp_cache_add( 'recent_comments', $comments, 'widget' );
	}
	echo $before_widget;
	echo $before_title . $title . $after_title;
	echo '<ul id = "recentcomments">';
	if ( $comments ) : foreach ( (array) $comments as $comment ) :
		echo '<li class="recentcomments">' . sprintf( __( '%1$s on%2$s' ), get_comment_author_link(), '<a href = "' . get_comment_link( $comment->comment_ID ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>' ) . '</li> ';
	endforeach; endif;
	echo '</ul>';
	echo $after_widget;
}

А в том месте, где хотите вывести вставьте код:

<?php get_recent_comments( [ 'number' => 10 ] ); ?>

Оставьте комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Прокрутить вверх
Пролистать наверх