Created
November 8, 2010 13:20
-
-
Save anonymous/667683 to your computer and use it in GitHub Desktop.
Code to create an checkbox of WP Taxonomy in Metabox Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkbox_state($term_id, $terms) | |
{ | |
foreach ($terms as $term): | |
if ($term_id == $term->term_id) | |
echo 'checked'; | |
endforeach; | |
} | |
function checkbox_taxonomy($taxonomy_name, $mb) | |
{ | |
$args = array('name'=>$taxonomy_name); | |
$taxonomy = array_pop(get_taxonomies( $args, 'objects')); | |
?> | |
<div id=five_columns class=checkbox_container> | |
<label class="checkbox-title"><?php echo $taxonomy->labels->name; ?><!--<span>(optional)</span>--></label> | |
<div class="panel"> | |
<?php | |
$terms = get_terms($taxonomy->name, 'orderby=name&hide_empty=0'); | |
$post_terms = wp_get_post_terms( $mb->current_post_id, $taxonomy->name); | |
$mb->the_field($taxonomy->name); | |
?> | |
<ul class="list:effect categorychecklist form-no-clear" id="effectchecklist"> | |
<?php foreach ($terms as $term): ?> | |
<li class="popular-category" id="<?php echo $taxonomy->name;?>"> | |
<label class="checkbox-label"> | |
<input type="checkbox" name="<?php $mb->the_name(); ?>[]" value="<?php echo $term->term_id; ?>"<?php checkbox_state($term->term_id, $post_terms); ?>> | |
<?php echo $term->name; ?> | |
</label> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<!--<select name="<?php $mb->the_name(); ?>"> | |
<?php foreach ($terms as $term): ?> | |
<option value="<?php echo $term->term_id; ?>"<?php $mb->the_select_state($term->term_id); ?> | |
<?php echo '>' . $term->name; ?> | |
</option> | |
<?php endforeach; ?> | |
</select>--> | |
</div> | |
<!--<span>Selecteer <?php echo $taxonomy->labels->name; ?></span>--> | |
<input class="add" type="text" name="312" value=""/> | |
<a href="#" class="button" style="" onclick="321">Add</a> | |
</div> | |
<?php | |
} | |
?> | |
<!-- usage --> | |
<?php | |
checkbox_taxonomy('problem', $mb); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment