I want to create my own template for comments, so I did run foreach
and this came out:
<dl class="commentlist">
<?php foreach ($comments as $comment) : ?>
<dt><?php printf(__('%s'), get_comment_author_link()) ?> <em><?php echo human_time_diff( get_comment_time('U'), current_time('timestamp') ); ?> <?php echo get_locale() == 'pl_PL' ? 'temu' : 'ago'; ?></em></dt>
<dd>
<?php if ($comment->comment_approved == '0') : ?>
<em>Komentarz czeka na zatwierdzenie</em><br />
<?php endif; ?>
<?php comment_text(); ?>
<?php comment_reply_link( array ( 'reply_text' => 'Reply this comment' ) ); ?>
</dd>
<?php endforeach; ?>
</dl>
All well, but I can’t get comment_reply_link
to work. I tried using solution found in WordPress Comment reply link does not appear, but it doesn’t work for me.
comment_reply_link( array('reply_text' => 'Reply this comment'), comment_ID(), the_ID() );
gives me some number (propably timestamp of the comment).
What can I do?
If you are using not using
wp_list_comments
but for instanceget_comments
and then run a for each, as you did above, the problem withcomment_reply_link
is the following:In the wordpress comment-template.php the
get_comment_reply_link
used bycomment_reply_link
has aNULL
value in$args['max_depth']
thus the below if statement:is always true and the function exits premature. Even if you set
'depth' => 1
. Because NULL is always smaller than 0,1,etc..You can not write a custom filter for
comment_reply_link
because the hook is called later in the function.The only way around I have found without changing the comment-template.php file was to do the following in my comment.php:
Then the link will show up.
Ok this is going to be a long answer:)
1.Create a commnets.php and add a following code:
Upload that file to your theme root directory (where your theme index.php is located).
2.Open your functions.php and add the following code:
3.Find your single.php file located also inside your theme root directory ,and call
your commnet form like so:
There is no such thing as a depth
0
comment. This usually happens when the native comment walker has been replaced, and the new walker class does not increment the$depth
variable correctly, so it defaults to0
. It is a common mistake. You might see this as thedepth-0
class appearing, or the depth being mistakenly 1 less than it should be.To remedy this, adjust the
start_el
function of any walker to increment both$depth
as well as the comment_depth global the same way the WP core implementation does. This may also resolve some related issues and PHP warnings.