Last active
July 9, 2018 08:02
-
-
Save dleone81/48abfd8549aaa7f7214fdad6d7cd1d72 to your computer and use it in GitHub Desktop.
Create custom template for comments in Wordpress. You can use the above code in functions.php during theme or plugin development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# comments.php | |
# update comments.php in child theme | |
<div class="comment-list"> | |
<?php | |
// ref: https://codex.wordpress.org/Function_Reference/wp_list_comments#Arguments | |
$args = [ | |
'walker' => null, | |
'max_depth' => '', | |
'style' => 'div', | |
'callback' => 'commentsHTML5', | |
'end-callback' => null, | |
'type' => 'all', | |
'reply_text' => 'Reply', | |
'page' => '', | |
'per_page' => '', | |
'avatar_size' => 32, | |
'reverse_top_level' => null, | |
'reverse_children' => '', | |
'format' => 'html5', // or 'xhtml' if no 'HTML5' theme support | |
'short_ping' => false, // @since 3.6 | |
'echo' => true // boolean, default is true | |
]; | |
wp_list_comments($args); | |
?> | |
</div><!-- .comment-list --> | |
# commentsHTML5 is the callback that you'll use to customize the comment template | |
# functions.php (or wherever you want) | |
function commentsHTML5(){ | |
$comment = get_comment(); | |
$id = $comment->comment_ID; | |
$author = $comment->comment_author; | |
$author_url = $comment->comment_author_url; | |
$date = $comment->comment_date; | |
$content = $comment->comment_content; | |
$o = ''; | |
?> | |
<div class="row"> | |
<div class="col col-2 col-12-small"> | |
<?php | |
$args = [ | |
'class' => 'image', | |
]; | |
echo get_avatar( $id, '96', '', $author, $args ); ?></div> | |
<div class="col col-10 col-12-small"> | |
<?php | |
$reply = __('Replied by', 'mrwooo-strata'); | |
$url = ($author_url == true ? $author_url : ''); | |
$on = __('on', 'mrwooo-strata'); | |
$str = '%s <a href="%s" title="'.$author.'">'.$author.'</a> %s '.$date; | |
$o .= '<p>'.$content.'</p>'; | |
$o .= '<small>'.sprintf($str, $reply, $url, $on).'</small>'; | |
echo $o; | |
?> | |
</div> | |
<!-- accordling to codex don't close the last tag --> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment