[英]How to wrap html tags around each field in comment form?
I currently have an array which is part of a custom function for a comment form, but would like to wrap tags around each field for styling purposes. 我目前有一个数组,该数组是用于注释表单的自定义函数的一部分,但希望将标签包装在每个字段周围以用于样式设计。 How would I achieve this?
我将如何实现? I have tried a few ways (echo etc..) which have thrown errors.
我尝试了几种抛出错误的方法(回声等)。
I currently have - 我目前有-
$fields = array(
'author' =>
'<p class="comment-form-author">' .
'<input id="author" name="author" type="text" size="30" placeholder="' . __( 'Your Name (required)', 'pumba' ) . '" />' .
'</p>',
'email' =>
'<p class="comment-form-email">' .
'<input id="email" name="email" type="text" size="30" placeholder="' . __( 'Your Email (will not be published)', 'pumba' ) . '" />' .
'</p>',
'url' =>
'<p class="comment-form-url">' .
'<input name="url" size="30" id="url" type="text" placeholder="' . __( 'Your Website (optional)', 'pumba' ) . '" />' .
'</p>',
);
I would like to wrap each of the 3 fields (separately) in a - 我想将3个字段分别包装在-
<div class="c4">............</div>
Many thanks 非常感谢
Like this: 像这样:
foreach($fields as $k => $v)
{
$fields[$k] = '<div class="c4">'.$v.'</div>';
}
? ?
Another way you can try with array_map: 您可以尝试使用array_map的另一种方法:
$fields = array_map(
function ($el) {
return "<div class=\"c4\">{$el}</div>";
},
$fields
);
There shouldn't be any problem doing this: 这样做应该没有任何问题:
$fields = array(
'author' =>
'<div class="c4"><p class="comment-form-author">' .
'<input id="author" name="author" type="text" size="30" placeholder="' . __( 'Your Name (required)', 'pumba' ) . '" />' .
'</p></div>',
'email' =>
'<div class="c4"><p class="comment-form-email">' .
'<input id="email" name="email" type="text" size="30" placeholder="' . __( 'Your Email (will not be published)', 'pumba' ) . '" />' .
'</p></div>',
'url' =>
'<div class="c4"><p class="comment-form-url">' .
'<input name="url" size="30" id="url" type="text" placeholder="' . __( 'Your Website (optional)', 'pumba' ) . '" />' .
'</p></div>',
);
Let me know if it works or not. 让我知道它是否有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.