John Davidson

php - Wordpress: Show up 'comment_form()' instead 'comment_reply_link()' in custom 'wp_list_comments()'

0 comments
Message:


I'm developing my own code to display the comment list and comment form.


What I need is to replace 'reply' button (only when is shown), with a comment form, next to the commentary to make the reply.


All the code I have so far is the following. Can someone help me fix it? Thanks.


    <?php 
$postid = XXX;

$comment_send = 'Send';
$comment_reply = 'Leave a Message';
$comment_reply_to = 'Reply';
$comment_author = 'Name';
$comment_email = 'E-Mail';
$comment_body = 'Comment';
$comment_url = 'Website';
$comment_cookies_1 = ' By commenting you accept the';
$comment_cookies_2 = ' Privacy Policy';
$comment_before = 'Registration isn\'t required.';
$comment_cancel = 'Cancel Reply';

$comments_args = array(
'fields' => array(
'author' => '<p class="comment-form-author"><br /><input id="author" name="author" aria-required="true" placeholder="' . $comment_author .'"></input></p>',
'email' => '<p class="comment-form-email"><br /><input id="email" name="email" placeholder="' . $comment_email .'"></input></p>',
'url' => '<p class="comment-form-url"><br /><input id="url" name="url" placeholder="' . $comment_url .'"></input></p>',
'cookies' => '<input type="checkbox" required>' . $comment_cookies_1 . '<a href="' . get_privacy_policy_url() . '">' . $comment_cookies_2 . '</a>',
),
'label_submit' => __( $comment_send ),
'title_reply' => __( $comment_reply),
'cancel_reply_link' => __( $comment_cancel ),
'comment_field' => '<p class="comment-form-comment"><br /><textarea id="comment" name="comment" aria-required="true" placeholder="' . $comment_body .'"></textarea></p>',
'comment_notes_before' => __( $comment_before),
'comment_notes_after' => ''
);

comment_form( $comments_args, $postid );
?>

<ol class="commentlist">
<?php wp_list_comments(array('callback' => 'custom_comments_format'), get_comments(array('post_id' => $post_id))); ?>

<?php function custom_comments_format($comment, $args, $depth){ ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author">
<?php echo get_avatar( $comment, 56 ); ?>
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author()) ?>
</div>
<div class="comment-moderation">
<?php if ($comment->comment_approved == '0') : ?>
<p><?php _e('Your comment is awaiting moderation.') ?></p>
<?php endif; ?>
</div>
<div class="comment-meta commentmetadata">
<p ><?php printf(__('%1$s at %2$s'), get_comment_date('j F, Y'), get_comment_time()) ?><?php edit_comment_link(__('(Edit)'),' ','') ?></p>
</div>
<div class="user-comment">
<?php comment_text() ?>
</div>
<div class="reply">
<?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
</div>
</div>
<?php } ?>
</ol>

Ps: The relation between a form and a reply comment is the comment_parent input. I can stack a new form instead the reply button, but I dont know how to set the comment_parent id into the comment_form( $comments_args, $postid ); as I did before to customize the form itself.


    <input type="hidden" name="comment_parent" id="comment_parent" value="XXX">



      <div class="reply">
<?php //comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))); ?>

<?php
if($depth < $args['max_depth']){
$comments_args = array(
'comment_field' => '<input type=\'hidden\' name=\'comment_parent\' id=\'comment_parent\' value=\''.get_comment_ID().'\' />'
);
comment_form( $comments_args, $postid );
}
?>
</div>


My Answer:
To display content in WordPress using PHP, you can use the following code snippet:

php
// The Loop
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
?>





}
} else {
// If no content is found
echo 'No content found.';
}
?>


This code will loop through the posts in WordPress and display the title and content of each post. If no content is found, it will display a message saying "No content found."

You can place this code in your theme files (e.g., single.php, index.php) to display content on your WordPress site.

Rate this post

4 of 5 based on 6661 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us