admin管理员组文章数量:1130349
One example of the comments.php is available here.
I have created comments.php file in my theme folder. In my content.php my HTML for displaying comment form looks like this:
<textarea name="name" rows="8" cols="80"></textarea>
<div class="t-comment-section">
<p>Full Name:</p> <input type="text" name="Full Name">
<p>Email:</p> <input type="text" name="Email address">
<p>Website:</p> <input type="text" name="Website url">
<a href=""><i class="fa fa-comment" aria-hidden="true"></i><span> Submit Comment </span></a>
</div>
How should I connect my comments.php to the HTML that will be used to display the comment form in my single.php or in short all the post pages that will appear?
One example of the comments.php is available here.
I have created comments.php file in my theme folder. In my content.php my HTML for displaying comment form looks like this:
<textarea name="name" rows="8" cols="80"></textarea>
<div class="t-comment-section">
<p>Full Name:</p> <input type="text" name="Full Name">
<p>Email:</p> <input type="text" name="Email address">
<p>Website:</p> <input type="text" name="Website url">
<a href=""><i class="fa fa-comment" aria-hidden="true"></i><span> Submit Comment </span></a>
</div>
How should I connect my comments.php to the HTML that will be used to display the comment form in my single.php or in short all the post pages that will appear?
1 Answer
Reset to default 1The comment_form() function is pretty customizable, and it accepts a variety of arguments. Take a look at these sample arguments, you can modify them to fit your needs:
$fields = array(
'author' =>
'<input name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .'" size="30" placeholder="'.__('Your name','text-domain').( $req ? ' (Required)' : '' ).'"/>',
'email' =>
'<input name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .'" size="30" placeholder="'.__('Your email','text-domain').( $req ? ' (Required)' : '' ).'"/>',
);
$args = array(
'id_form' => 'commentform',
'class_form' => 'comment-form',
'id_submit' => 'submit',
'class_submit' => 'submit',
'name_submit' => 'submit',
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
'title_reply' => '',
'title_reply_to' => __( 'Reply to %s','text-domain' ),
'cancel_reply_link' => __( 'Cancel comment','text-domain' ),
'label_submit' => __( 'Post comment','text-domain' ),
'format' => 'xhtml',
'comment_field' => '<textarea id="comment" name="comment" placeholder="'.__('Comment text','text-domain').'" cols="45" rows="8" aria-required="true">' .'</textarea>',
'logged_in_as' => '<p class="logged-in-as">' .
sprintf(
__( 'Logged in as %1$s. <a href="%2$s" title="%3$s">%4$s</a>', 'text-domain'),
$user_identity,
wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ),
__('Log out?','text-domain'),
__('Click to log out.','text-domain')
) . '</p>',
'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.','text-domain' ) .'</p>',
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
);
comment_form( $args );
You can add any class to the elements, or wrap them in <div> or <p>.
If you want to move the text area below the other fields, you can use the comment_form_fields filter:
function move_comment_field_to_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );
UPDATE
To include the comment form in your content.php file, save the first code in your comment.php, and then call the form in the loop this way:
if ( comments_open() || '0' != get_comments_number() ) {
comments_template();
}
This will append the comment.php to your content.
One example of the comments.php is available here.
I have created comments.php file in my theme folder. In my content.php my HTML for displaying comment form looks like this:
<textarea name="name" rows="8" cols="80"></textarea>
<div class="t-comment-section">
<p>Full Name:</p> <input type="text" name="Full Name">
<p>Email:</p> <input type="text" name="Email address">
<p>Website:</p> <input type="text" name="Website url">
<a href=""><i class="fa fa-comment" aria-hidden="true"></i><span> Submit Comment </span></a>
</div>
How should I connect my comments.php to the HTML that will be used to display the comment form in my single.php or in short all the post pages that will appear?
One example of the comments.php is available here.
I have created comments.php file in my theme folder. In my content.php my HTML for displaying comment form looks like this:
<textarea name="name" rows="8" cols="80"></textarea>
<div class="t-comment-section">
<p>Full Name:</p> <input type="text" name="Full Name">
<p>Email:</p> <input type="text" name="Email address">
<p>Website:</p> <input type="text" name="Website url">
<a href=""><i class="fa fa-comment" aria-hidden="true"></i><span> Submit Comment </span></a>
</div>
How should I connect my comments.php to the HTML that will be used to display the comment form in my single.php or in short all the post pages that will appear?
1 Answer
Reset to default 1The comment_form() function is pretty customizable, and it accepts a variety of arguments. Take a look at these sample arguments, you can modify them to fit your needs:
$fields = array(
'author' =>
'<input name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .'" size="30" placeholder="'.__('Your name','text-domain').( $req ? ' (Required)' : '' ).'"/>',
'email' =>
'<input name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .'" size="30" placeholder="'.__('Your email','text-domain').( $req ? ' (Required)' : '' ).'"/>',
);
$args = array(
'id_form' => 'commentform',
'class_form' => 'comment-form',
'id_submit' => 'submit',
'class_submit' => 'submit',
'name_submit' => 'submit',
'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
'title_reply' => '',
'title_reply_to' => __( 'Reply to %s','text-domain' ),
'cancel_reply_link' => __( 'Cancel comment','text-domain' ),
'label_submit' => __( 'Post comment','text-domain' ),
'format' => 'xhtml',
'comment_field' => '<textarea id="comment" name="comment" placeholder="'.__('Comment text','text-domain').'" cols="45" rows="8" aria-required="true">' .'</textarea>',
'logged_in_as' => '<p class="logged-in-as">' .
sprintf(
__( 'Logged in as %1$s. <a href="%2$s" title="%3$s">%4$s</a>', 'text-domain'),
$user_identity,
wp_logout_url( apply_filters( 'the_permalink', get_permalink( ) ) ),
__('Log out?','text-domain'),
__('Click to log out.','text-domain')
) . '</p>',
'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.','text-domain' ) .'</p>',
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
);
comment_form( $args );
You can add any class to the elements, or wrap them in <div> or <p>.
If you want to move the text area below the other fields, you can use the comment_form_fields filter:
function move_comment_field_to_bottom( $fields ) {
$comment_field = $fields['comment'];
unset( $fields['comment'] );
$fields['comment'] = $comment_field;
return $fields;
}
add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );
UPDATE
To include the comment form in your content.php file, save the first code in your comment.php, and then call the form in the loop this way:
if ( comments_open() || '0' != get_comments_number() ) {
comments_template();
}
This will append the comment.php to your content.
本文标签: Create commentsphp form of custom HTML code
版权声明:本文标题:Create comments.php form of custom HTML code 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749089267a2314262.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论