我正在尝试在wordpress中动态插入HTML标记。我使用下面的代码获取自定义分类颜色的所有术语,它工作正常:
PHP:
$terms = get_terms("colour");
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
echo "<ul>";
foreach ( $terms as $term ) {
echo "<li>" . $term->name . "</li>";
}
echo "</ul>";
}
但是我希望Html呈现如下:
<label><input type="checkbox" rel="Cream"/> Cream </label>
<label><input type="checkbox" rel="White"/> White </label>
<label><input type="checkbox" rel="Yellow"/> Yellow </label>
请帮助我如何实现这一目标?
答案 0 :(得分:0)
$terms = get_terms("colour");
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
$html = '';
foreach ( $terms as $term ) {
$html .= '<label><input type="checkbox" rel="' . $term->name .'"/> '.$term->name.' </label>';
}
echo $html;
}
答案 1 :(得分:0)
$terms = get_terms("colour");
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
echo '<label><input type="checkbox" rel="'.$term->name.'"/> '.$term->name.' </label>';
}
}