tonyoravet
Member
Posted 6 months 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?
George Stephanis
Member
Posted 6 months ago #
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');
}
});
});
George Stephanis
Member
Posted 6 months ago #
tonyoravet
Member
Posted 6 months 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?
tonyoravet
Member
Posted 6 months 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>
George Stephanis
Member
Posted 6 months ago #
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
tonyoravet
Member
Posted 6 months 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
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!!
tonyoravet
Member
Posted 4 months 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]
antonio nardelli
Member
Posted 3 months 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?
antonio nardelli
Member
Posted 3 months 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...