Created
May 27, 2018 20:09
-
-
Save asuh/342513bfecc141f7e9e279567b7b0649 to your computer and use it in GitHub Desktop.
Walker_Comment overwrite for WordPress
This file contains 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
<?php | |
class comments_reloaded extends \Walker_Comment { | |
var $tree_type = 'comment'; | |
var $db_fields = array( | |
'parent' => 'comment_parent', | |
'id' => 'comment_ID' | |
); | |
// start_lvl – Wrapper for child comments list, starts the list before the elements are added. | |
public function start_lvl( &$output, $depth = 0, $args = array() ) { | |
$GLOBALS['comment_depth'] = $depth + 2; ?> | |
<ol class="children comments-list"> | |
<?php } | |
// end_lvl – closing wrapper for child comments list | |
public function end_lvl( &$output, $depth = 0, $args = array() ) { | |
$GLOBALS['comment_depth'] = $depth + 2; ?> | |
</ol><!-- .children --> | |
<?php } | |
// start_el – HTML for comment template | |
public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) { | |
$depth++; | |
$GLOBALS['comment_depth'] = $depth; | |
$GLOBALS['comment'] = $comment; | |
$parent_class = ( empty( $args['has_children'] ) ? '' : 'parent' ); | |
if ( 'article' == $args['style'] ) { | |
$tag = 'article'; | |
$add_below = 'comment'; | |
} else { | |
$tag = 'article'; | |
$add_below = 'comment'; | |
} ?> | |
<li <?php comment_class(empty( $args['has_children'] ) ? '' :'parent') ?> id="comment-<?php comment_ID() ?>" itemprop="comment" itemscope itemtype="http://schema.org/Comment"> | |
<article class="comment-body"> | |
<footer class="comment-meta post-meta" role="complementary"> | |
<h2 class="comment-author"> | |
<figure class="gravatar"><?php echo get_avatar( $comment, 65, '', 'Author’s gravatar' ); ?></figure> | |
<a class="comment-author-link" href="<?php comment_author_url(); ?>" itemprop="author"><?php comment_author(); ?></a> | |
</h2> | |
<a href="#comment-<?php comment_ID() ?>">#</a> <time class="comment-meta-item" datetime="<?php comment_date('Y-m-d') ?>T<?php comment_time('H:iP') ?>" itemprop="datePublished"><?php comment_date('F jS Y') ?></time> | |
<?php edit_comment_link('<p class="comment-meta-item">Edit this comment</p>','',''); ?> | |
<?php if ($comment->comment_approved == '0') : ?> | |
<p class="comment-meta-item">Your comment is awaiting moderation.</p> | |
<?php endif; ?> | |
</footer> | |
<div class="comment-content post-content" itemprop="text"> | |
<?php comment_text() ?> | |
<?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?> | |
</div> | |
</article> | |
<?php } | |
// end_el – closing HTML for comment template | |
public function end_el(&$output, $comment, $depth = 0, $args = array() ) { ?> | |
</li> | |
<?php } | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment