是否有一种像样的标准WP方式将3个标准字段(名称、电子邮件、网站)包装在一个div中?我正在使用bootstrap,希望他们在自己的一排。
示例:
<?php
$fields = array(
\'author\' =>
\'<div class="col-md-4 comment-form-author">\' .
\'<input placeholder="\'.__( \'Name\', \'_lp\' ).\' \'.( $req ? \' ( Required )\' : \'\' ) .\'" id="author" name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .
\'" size="30"\' . $aria_req . \' /></div>\',
\'email\' =>
\'<div class="col-md-4 comment-form-email">\'.
\'<input placeholder="\'.__( \'Email\', \'_lp\' ).\' \'.( $req ? \' ( Required )\' : \'\' ) .\'" id="email" name="email" type="text" value="\' . esc_attr( $commenter[\'comment_author_email\'] ) .
\'" size="30"\' . $aria_req . \' /></div>\',
\'url\' =>
\'<div class="col-md-4 comment-form-url">\' .
\'<input placeholder="\'.__( \'Website\', \'_lp\' ).\' \'.( $req ? \' ( Required )\' : \'\' ) .\'" id="url" name="url" type="text" value="\' . esc_attr( $commenter[\'comment_author_url\'] ) .
\'" size="30" /></div>\',
);
?>
本来我可以打开
<div class="row">
在author div之前,然后是closign
</div>
关闭url div后。。。但是,如果这三个都不是输出的,我会破坏HTML。
SO网友:1Up
回答我自己的问题-我不能百分之百肯定这是安全的,但我使用提供的before/after actions来放入before/after div,如下所示:
//for the comment wrapping functions - ensures HTML does not break.
$comment_open_div = 0;
/**
* Creates an opening div for a bootstrap row.
* @global int $comment_open_div
*/
function _lp_before_comment_fields(){
global $comment_open_div;
$comment_open_div = 1;
echo \'<div class="row">\';
}
/**
* Creates a closing div for a bootstrap row.
* @global int $comment_open_div
* @return type
*/
function _lp_after_comment_fields(){
global $comment_open_div;
if($comment_open_div == 0)
return;
echo \'</div>\';
}
add_action(\'comment_form_before_fields\', \'_lp_before_comment_fields\');
add_action(\'comment_form_after_fields\', \'_lp_after_comment_fields\');
这将导致
<div class="row">
<!--the fields and stuff-->
</div>
如果有更好的解决方案,我很想知道!