[英]Dynamically inserting Html tags in Wordpress
我正在嘗試在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>
請幫助我如何實現這一目標?
$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;
}
$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>';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.