comments - comment_reply_link not work with me

admin2025-01-07  5

I have this code that get me last comments in my site :

function bg_recent_comments($no_comments = 30, $comment_len = 80, $avatar_size = 48) {
                        $comments_query = new WP_Comment_Query();
                        $comments = $comments_query->query( array( 'number' => $no_comments , 'status' => 'approve') );
                        $comm = '';
                        if ( $comments ) : foreach ( $comments as $comment ) :
                            $comm .= '<li id="comment-160546">
                            <br><a href="'.get_permalink($comment->comment_post_ID).'" style="font-family:droid arabic kufi;text-align: center;font-style: italic;font-weight: bold;font-size: 15px;">'.get_the_title($comment->comment_post_ID).'</a><br><br>
                                <div class="comment byuser comment-author-hasan-ly odd alt thread-odd thread-alt depth-1 comment-wrap">
                                    <div class="comment-avatar">'.get_avatar( $comment->comment_author_email, $avatar_size ).'</div>
                                    <div class="comment-content">
                                        <div class="author-comment">
                                            <cite class="fn">'.get_comment_author( $comment->comment_ID ).'</cite>                  
                                            <div class="comment-meta commentmetadata"><a href="' . get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID . '">Post URL</a></div><!-- ment-meta mentmetadata -->
                                            <div class="clear"></div>
                                        </div>
                                        <p>' . $comment->comment_content . '</p>
                                    </div>
                                </div><!-- #comment-##  --><br>
                            </li>';
                        endforeach; else :
                            $comm .= 'No comments.';
                        endif;
                        echo $comm; 
                    }

Now my problem is when add comment_reply_link to can any user replay to this comment. its now show the form reply,

When var_dump comment_reply_link its return me NULL.

How can solve it

I have this code that get me last comments in my site :

function bg_recent_comments($no_comments = 30, $comment_len = 80, $avatar_size = 48) {
                        $comments_query = new WP_Comment_Query();
                        $comments = $comments_query->query( array( 'number' => $no_comments , 'status' => 'approve') );
                        $comm = '';
                        if ( $comments ) : foreach ( $comments as $comment ) :
                            $comm .= '<li id="comment-160546">
                            <br><a href="'.get_permalink($comment->comment_post_ID).'" style="font-family:droid arabic kufi;text-align: center;font-style: italic;font-weight: bold;font-size: 15px;">'.get_the_title($comment->comment_post_ID).'</a><br><br>
                                <div class="comment byuser comment-author-hasan-ly odd alt thread-odd thread-alt depth-1 comment-wrap">
                                    <div class="comment-avatar">'.get_avatar( $comment->comment_author_email, $avatar_size ).'</div>
                                    <div class="comment-content">
                                        <div class="author-comment">
                                            <cite class="fn">'.get_comment_author( $comment->comment_ID ).'</cite>                  
                                            <div class="comment-meta commentmetadata"><a href="' . get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID . '">Post URL</a></div><!-- .comment-meta .commentmetadata -->
                                            <div class="clear"></div>
                                        </div>
                                        <p>' . $comment->comment_content . '</p>
                                    </div>
                                </div><!-- #comment-##  --><br>
                            </li>';
                        endforeach; else :
                            $comm .= 'No comments.';
                        endif;
                        echo $comm; 
                    }

Now my problem is when add comment_reply_link to can any user replay to this comment. its now show the form reply,

When var_dump comment_reply_link its return me NULL.

How can solve it

Share Improve this question asked Mar 17, 2016 at 13:36 user3507956user3507956 113 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The function comment_reply_link echos the function get_comment_reply_link. If you look at the source code you see, that up to 3 arguments are needed for a proper functionality.

  1. $args an array of optional arguments that overwrite the default values
  2. $comment an optional comment_id or WP_Comment object the comment should reply to.
  3. $post an optional post_id or WP_Post object where the comment is going to be displayed on.

If the function returns null, it cannot figure out the relating $post. Try to add this parameter to your function call, e.g. comment_reply_link(null, null, $post_id) or $comm.= get_comment_reply_link(null, $comment); (within your foreach loop).

If the function returns false, comments are disabled for this post.

Source: developer.wordpress.org

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736257754a462.html

最新回复(0)