Title: Оформления комментариев (comments.php
Last modified: 25.12.2014

---

# Оформления комментариев (comments.php

 *  [Narek-T](https://ru.wordpress.org/support/users/narek-t/)
 * (@narek-t)
 * [11 лет, 10 месяцев назад](https://ru.wordpress.org/support/topic/%d0%9e%d1%84%d0%be%d1%80%d0%bc%d0%bb%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba%d0%be%d0%bc%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b8%d0%b5%d0%b2-commentsphp/)
 * Здравствуйте. Голову ломаю над кодом, не могу разобраться самостоятельно, нужна
   ваша помощь (в php не силен, только учу).
    Вопрос такой, возможно ли оформить
   комментарии тегами какими я хочу, а не такими какие предлагает мне wordpress ?
   Например структура которую я хочу получать для каждого коммента :
 *     ```
       <div class="comment">
           <a href="ссылка на страницу автора" class="userpic"><img src="http://placehold.it/70x70" alt=""></a>
           <div class="comment-inner">
               <p class="name-and-date"><a href="#">Имя автора</a> | <time>дата</time></p>
               <p>Комментарий...</p>
               <a href="ссылка ответить" class="answer">Ответить на комментарий</a>
           </div>
       </div>
       ```
   
 * Дополнительно нужно делать так, что бы форма не показывалась неавторизованным
   посетителям.
    Голова уже не варит, помогите примером пожалуйста, если не сложно.

Просмотр 3 ответов — с 1 по 3 (всего 3)

 *  [gustavmc](https://ru.wordpress.org/support/users/gustavmc/)
 * (@gustavmc)
 * [11 лет, 10 месяцев назад](https://ru.wordpress.org/support/topic/%d0%9e%d1%84%d0%be%d1%80%d0%bc%d0%bb%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba%d0%be%d0%bc%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b8%d0%b5%d0%b2-commentsphp/#post-158362)
 * В файле comments.php оберните свой код в
 *     ```
       <?php if (!is_user_logged_in()) : ?>
       <?php endif; ?>
       ```
   
 * Там же и измените форму
 *  [cats_456](https://ru.wordpress.org/support/users/cats_456/)
 * (@cats_456)
 * [11 лет, 10 месяцев назад](https://ru.wordpress.org/support/topic/%d0%9e%d1%84%d0%be%d1%80%d0%bc%d0%bb%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba%d0%be%d0%bc%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b8%d0%b5%d0%b2-commentsphp/#post-158429)
 * Для вывода комментариев можно задать колбэк функцию как сделано, например, в 
   Twenty Twelve
 *     ```
       <ol class="commentlist">
       			<?php wp_list_comments( array( 'callback' => 'twentytwelve_comment', 'style' => 'ol' ) ); ?>
       		</ol><!-- .commentlist -->
       ```
   
 * В этой же функции задается как выводить комментарии: списком или div. Вывод:
 *     ```
       /**
        * Template for comments and pingbacks.
        *
        * To override this walker in a child theme without modifying the comments template
        * simply create your own twentytwelve_comment(), and that function will be used instead.
        *
        * Used as a callback by wp_list_comments() for displaying the comments.
        *
        * @since Twenty Twelve 1.0
        */
       function twentytwelve_comment( $comment, $args, $depth ) {
       	$GLOBALS['comment'] = $comment;
       	switch ( $comment->comment_type ) :
       		case 'pingback' :
       		case 'trackback' :
       		// Display trackbacks differently than normal comments.
       	?>
       	<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
       		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
       	<?php
       			break;
       		default :
       		// Proceed with normal comments.
       		global $post;
       	?>
       	<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
       		<article id="comment-<?php comment_ID(); ?>" class="comment">
       			<header class="comment-meta comment-author vcard">
       				<?php
       					echo get_avatar( $comment, 44 );
       					printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
       						get_comment_author_link(),
       						// If current post author is also comment author, make it known visually.
       						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
       					);
       					printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
       						esc_url( get_comment_link( $comment->comment_ID ) ),
       						get_comment_time( 'c' ),
       						/* translators: 1: date, 2: time */
       						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
       					);
       				?>
       			</header><!-- .comment-meta -->
   
       			<?php if ( '0' == $comment->comment_approved ) : ?>
       				<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
       			<?php endif; ?>
   
       			<section class="comment-content comment">
       				<?php comment_text(); ?>
       				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
       			</section><!-- .comment-content -->
   
       			<div class="reply">
       				<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>&darr;</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
       			</div><!-- .reply -->
       		</article><!-- #comment-## -->
       	<?php
       		break;
       	endswitch; // end comment_type check
       }
       ```
   
 * Обычно нет смысла делать это (и это может быть вредно), комментарии можно оформить
   при помощи css.
 *  Автор [Narek-T](https://ru.wordpress.org/support/users/narek-t/)
 * (@narek-t)
 * [11 лет, 10 месяцев назад](https://ru.wordpress.org/support/topic/%d0%9e%d1%84%d0%be%d1%80%d0%bc%d0%bb%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba%d0%be%d0%bc%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b8%d0%b5%d0%b2-commentsphp/#post-158441)
 * Спасибо за ответы, а почему может быть вредно?

Просмотр 3 ответов — с 1 по 3 (всего 3)

 Тема «Оформления комментариев (comments.php» закрыта для новых ответов.

## Метки

 * [comments](https://ru.wordpress.org/support/topic-tag/comments/)
 * [комменты](https://ru.wordpress.org/support/topic-tag/%d0%ba%d0%be%d0%bc%d0%bc%d0%b5%d0%bd%d1%82%d1%8b/)
 * [оформление](https://ru.wordpress.org/support/topic-tag/%d0%be%d1%84%d0%be%d1%80%d0%bc%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5/)

 * Форум: [Проблемы и решения](https://ru.wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 ответа
 * 3 участника
 * Последний ответ: [Narek-T](https://ru.wordpress.org/support/users/narek-t/)
 * Последняя активность: [11 лет, 10 месяцев назад](https://ru.wordpress.org/support/topic/%d0%9e%d1%84%d0%be%d1%80%d0%bc%d0%bb%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba%d0%be%d0%bc%d0%bc%d0%b5%d0%bd%d1%82%d0%b0%d1%80%d0%b8%d0%b5%d0%b2-commentsphp/#post-158441)
 * Статус: нерешённая

## Темы

### Самые популярные темы

### Темы без ответов

### Без вопроса

### Решённые

### Нерешённые

### Все темы
