• Is there a way to have the categories in the post write screen to be able to collapse. I have a client that has about 755 categories (I know…) but these are vehicle makes and models. Is there a way to collapse everything but the parent categories and then expand those parents to show children on the fly?

Viewing 11 replies - 1 through 11 (of 11 total)
  • A little js should do it, really.

    Give this a go … it worked for me:

    jQuery(document).ready(function($){
            $('#categorychecklist ul').hide();
            $('#categorychecklist input[type="checkbox"]:checked').parents('li').children('ul').show();
            $('#categorychecklist input[type="checkbox"]').change(function(){
                    if( $(this).attr('checked') ){
                            $(this).parents('li').children('ul').show();
                    }else{
                            $(this).parents('li').children('ul').hide().find('input[type="checkbox"]').removeAttr('checked');
                    }
            });
    });

    Thread Starter tonyoravet

    (@tonyoravet)

    Thanks George! I have this in my code now

    add_action( 'admin_footer', 'checkboxstuff', 50 );
    
    function checkboxstuff(){
    
    jQuery(document).ready(function($){
            $('#categorychecklist ul').hide();
            $('#categorychecklist input[type="checkbox"]:checked').parents('li').children('ul').show();
            $('#categorychecklist input[type="checkbox"]').change(function(){
                    if( $(this).attr('checked') ){
                            $(this).parents('li').children('ul').show();
                    }else{
                            $(this).parents('li').children('ul').hide().find('input[type="checkbox"]').removeAttr('checked');
                    }
            });
    });

    But it doesn’t seem to be working right.

    Any ideas?

    Thread Starter tonyoravet

    (@tonyoravet)

    Figured this out…add this code to the admin-footer.php file. Be careful if you upgrade though as this script below will need to be added back in unless there is a simple way to add this into a functions.php file somehow:

    <script type="text/javascript">
    
    jQuery(document).ready(function($){
           $('#categorychecklist ul').hide();
           $('#categorychecklist input[type="checkbox"]:checked').parents('li').children('ul').show();
           $('#categorychecklist input[type="checkbox"]').change(function(){
                   if( $(this).attr('checked') ){
                           $(this).parents('li').children('ul').show();
                   }else{
                           $(this).parents('li').children('ul').hide().find('input[type="checkbox"]').removeAttr('checked');
                   }
           });
    });
    </script>

    Please don’t hack core. Especially when it can be done just as easily from within a plugin or your theme’s functions.php file.

    http://codex.wordpress.org/images/b/b3/donthack.jpg

    Thread Starter tonyoravet

    (@tonyoravet)

    George,

    I don’t normally do that….and after looking at this a little further I figured out how to include it into the themes functions.php file.

    Thanks for your help!
    Tony

    Tonyoravet,

    Can you post an update of how you got this working in the functions.php file? I have 6 parent categories that hold about 250 child categories. I would really like to collapse those parent categories in the admin panel.

    Thanks!!

    Thread Starter tonyoravet

    (@tonyoravet)

    Ceh,

    Sure….

    I created a separate file and called it expanding-categories.php and included it in my functions.php file.

    The code to include it in the functions file looks like this:
    require_once ($includes_path . '/custom/expanding-categories.php');

    The code for the expanding-categories.php looks like this:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Hi, this is the best solution i found, thank you for sharing!!!
    I have a question, this is my situation:
    –1
    —2
    —-3
    Now when i click on 1,2,3 al 3 cats are checked, but i need to check only cat 3. How can i do?
    Then, if i rechek cat 1, is there a way to uncheck all sottocategory checked?

    Help please!!
    with this `jQuery(document).ready(function($){
    $(‘#categorychecklist ul’).hide();
    $(‘#categorychecklist input[type=”checkbox”]:checked’).parents(‘li’).show();
    $(‘#categorychecklist input’).change(function(){
    if( $(this).attr(‘checked’) ){
    $(this).parents(‘li’).children(‘ul’).show();
    }
    $(this).parents(‘li’).css(“color”, “red”).find(‘input[type=”checkbox”]’).removeAttr(‘checked’);
    });

    });`
    i show all subcats but then i can’t check nothing because removeAttr('checked'); uncheck all.
    The problem is to uncheck only parent categories…

    This works perfectly for what you’re trying to achieve…

    http://wordpress.org/extend/plugins/intuitive-category-checklist/screenshots/

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Collapsing Category in Post Write Screen’ is closed to new replies.