我有一个层次分类列表,如:
A (Parent Category)
- B (Child Category)
- C (Child Category)
- D (Child Category)
B (Parent Category)
- E (Child Category)
- F (Child Category)
如果父类别有子类别,那么父类别也有子类别的ID,如<input id="parent_1(ID)" class="checkbox" type="checkbox" name="parent_1(ID)" checked="checked" onchange="toggle( 1 (ID of the Parent Category), Array( 4, 3 (Both ID\'s of the Child Categorys), 999 ) )">
因此,当检查父类别时,也会检查子类别。Wordpress的旧函数get\\u children\\u categories按预期工作,java通过识别id来检查孩子。
但我的问题是,函数get\\u children\\u categories被取消了,而新函数get\\u term\\u children不起作用。
旧代码看起来是这样的:
class Walker_Category extends Walker
{
var $tree_type = \'category\';
var $db_fields = array (\'parent\' => \'parent\', \'id\' => \'term_id\');
function start_lvl($output, $depth, $args) {
if ( \'list\' != $args[\'style\'] )
return $output;
$indent = str_repeat("\\t", $depth);
$output .= "$indent<ul class=\'children\'>\\n";
return $output;
}
....................
function start_el($output, $category, $depth, $args)
{
extract($args);
$cat_name = esc_attr($category->name);
$cat_name = apply_filters( \'list_cats\', $cat_name, $category );
$children = substr( get_category_children( $category->term_id, \'\', \', \'), 0, -2 );
li><input type=\'checkbox\' onchange=\'toggle( {$category->term_id}, Array( $children, 999 ) )\'
.................
但当我更改代码时,如:$children = get_term_children( (int) $category->term_id, $category);
"<li><input type=\'checkbox\' onchange=\'toggle( {$category->term_id}, Array( $children...
它只给出0分。打印时,\\r会输出具有子类别id的数组,如: $children = get_term_children( (int) $category->term_id, \'category\');
$children = print_r( $children );
输出为: Array ( [0] => 3 [1] => 4 ) Array ( ) Array ( ) Array ( [0] => 6 ) Array ( )
有人知道我如何发布它吗?我已经做了几个小时了,没有主动提出来。或者,也可以有另一种解决方案来检查子类别。谢谢你的帮助。。。