我试图只显示已选中的类别,其他类别未选中。我正在使用循环,但它不能正常工作。我创建如下代码:
<tr>
<th><label><?php _e("Category:"); ?></label></th>
<td>
<?php
$args = array(
\'child_of\' => get_cat_ID(single_cat_title( \'\', false )),
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'hide_empty\' => 1,
\'hierarchical\' => 1,
\'exclude\' => \'\',
\'include\' => \'\',
\'number\' => \'\',
\'taxonomy\' => \'category\',
\'pad_counts\' => false
);
?>
<?php $categories = get_categories( $args ); ?>
<?php
$category_explode = get_the_author_meta( \'Category\', $user->ID );
//output 4,5,16
$cat_ex = explode(\',\',$category_explode);
foreach ($cat_ex as $cat_expld) {
foreach ($categories as $cat) {
?>
<label> <input type="checkbox" name="category[]" <?php if($cat_expld==$cat->cat_ID){ echo "checked=\'checked\'"; } ?> value="<?php echo $cat->cat_ID; ?>" ><?php echo $cat->cat_name; ?>
</label>
<?php } } ?>
</td>
</tr>