WordPress.org

Ready to get started?Download WordPress

Forums

Collapsing Category in Post Write Screen (12 posts)

  1. tonyoravet
    Member
    Posted 2 years ago #

    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?

  2. 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');
                    }
            });
    });

  3. tonyoravet
    Member
    Posted 2 years ago #

    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?

  4. tonyoravet
    Member
    Posted 2 years ago #

    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>
  5. 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

  6. tonyoravet
    Member
    Posted 2 years ago #

    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

  7. ceh
    Member
    Posted 2 years ago #

    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!!

  8. tonyoravet
    Member
    Posted 2 years ago #

    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]

  9. antonio nardelli
    Member
    Posted 2 years ago #

    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?

  10. antonio nardelli
    Member
    Posted 2 years ago #

    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...

  11. paa1605
    Member
    Posted 1 year ago #

    This works perfectly for what you're trying to achieve...

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

Topic Closed

This topic has been closed to new replies.

About this Topic