Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I know it is possible to change the WordPress category list to radio buttons in the admin panel for posts, but I would like to make the just the Parents radio buttons and the sub categories or children checkboxs... something like this.

<ul>
    <li><input type="radio"> Category 1
        <ul class="children">
        <li><input type="checkbox">Category 1 - Sub Cat 1</label></li>
        <li><input type="checkbox">Category 1 - Sub Cat 2</label></li>
        </ul>
    </li>
    <li><input type="radio"> Category 2</li>
    <li><input type="radio"> Category 3</li>
    <li><input type="radio"> Category 4
        <ul class="children">
        <li><input type="checkbox">Category 4 - Sub Cat 1</label></li>
        <li><input type="checkbox">Category 4 - Sub Cat 2</label></li>
        </ul>
    </li>
    <li><input type="radio"> Category 5</li>
</ul>

I don't really want to mess around with the core files and wondered if anyone knows a way to override the output via the theme functions or another method.

share|improve this question

migrated from stackoverflow.com Oct 2 '11 at 13:46

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers 2

I'm pretty sure you could use JavaScript to do this for you very simply. I'd try this out:

function convert_root_cats_to_radio()
{
    global $post_type;

    if ( 'post' != $post_type )
        return;
    ?>
    <script type="text/javascript">
    jQuery("#categorychecklist>li>label input").each(function(){
        this.type = 'radio';
    });
    </script>
    <?php
}
add_action( 'admin_footer-post.php', 'convert_root_cats_to_radio' );
add_action( 'admin_footer-post-new.php', 'convert_root_cats_to_radio' );

What this does is loops through the hierarchy and converts the top level items to radio buttons. If you need to strictly enforce this, the javascript won't be a good solution because the root-level categories can still be selected under the popular tab.

Check out this plugin, too, to keep the hierarchy after saving: http://wordpress.org/extend/plugins/category-checklist-tree/

If you need something a little more enforceable, you'll need a custom plugin to that. The above mentioned plugin would event be a great place to start in that endeavor!

Cheers~

share|improve this answer
    
Answering a similar question, I'm suggesting removing the "Most used" tab: jQuery('#category-tabs .hide-if-no-js').remove(); –  brasofilo Jul 14 '12 at 21:37
add comment

If the function use a walker type, then override by an extended child class of the walker.

If you do this, you can control how the child class will echo the html. You can style it the way you want it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.