custom шаблон для комментариев

6.01.10 / Категории Uncategorized | Оставить комментарий

Как изменить стандартный шаблон комментариев?

Добавляем следующий код в functions.php, который лежит внутри нашей темы.

<?php
   function mytheme_comment($comment, $args, $depth) {
   $GLOBALS['comment'] = $comment; ?>
   <li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
     <div id="comment-<?php comment_ID(); ?>">
      <div class="comment-author vcard">
         <?php echo get_avatar($comment,$size='48',$default='<path_to_url>' ); ?>
 
         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
      </div>
      <?php if ($comment->comment_approved == '0') : ?>
         <em><?php _e('Your comment is awaiting moderation.') ?></em>
         <br />
      <?php endif; ?>
 
      <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'  ','') ?></div>
 
      <?php comment_text() ?>
 
      <div class="reply">
         <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
      </div>
     </div>
<?php
        }
?>

Если добавляете вверх или в самый низ файла, осторожно с пробелами. Если добавить пару пробелов после кода, то потом при logout будет выводиться ошибка.

Теперь меняем строку

<?php wp_list_comments(); ?>

в файле comments.php, который также лежит в папке с темой, на строку

<?php wp_list_comments('type=comment&callback=mytheme_comment'); ?>

Все, теперь в functions.php вы можете изменить внешний вид ваших комментариев.

Вы можете сослаться на эту статью:
http://www.rantiev.com/custom-comments-template/trackback/

Комментарии

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