function has_child($id)
{
    $sub_args = array('taxonomy' => 'product_cat', 'hide_empty' => 0, 'parent' => $id);
    $pro_sub_cat = get_categories($sub_args);
    if ($pro_sub_cat) {
        echo '<ul class="children">';
        foreach ($pro_sub_cat as $psc) {
            //            $sub_term_link = get_term_link( $psc->term_id );
            echo '<li><a href="' . get_term_link($psc->slug, 'product_cat') . '">' . $psc->name . '</a>';
            has_child($psc->term_id);
            echo '</li>';
        }
        echo '</ul>';
    }
}
<?php

$default_id = 0;
// $default_id = 81;
$id = isset($_POST['id']) ? intval($_POST['id']) : $default_id;
include 'sql_helper.php';
include 'conn.php';
$result = array();
$query = select_query($_fields_collections, $_t_collections, "parent_id={$id}");
$rs = my_mysql_query($query);
while ($row = my_mysql_fetch_array($rs)) {
    $row['state'] = has_child($row['id']) ? 'closed' : 'open';
    array_push($result, $row);
}
echo json_encode($result);
Exemplo n.º 3
0
function list_categories($work_cates, $sub = "&nbsp;&nbsp;&nbsp;&nbsp;")
{
    foreach ($work_cates as $work_cate) {
        ?>
                              				<tr>
                                                <td><?php 
        echo $work_cate['id'];
        ?>
</td>

												<td><?php 
        echo $work_cate['name'];
        ?>
</td>
                                                <td><?php 
        if ($work_cate['type'] == 2) {
            echo "单篇文章";
        } else {
            echo "多篇文章";
        }
        ?>
</td>
												<td class="hidden-480">
													<div class="hidden-sm hidden-xs action-buttons">
														<a class="green" href="<?php 
        echo site_url('admin/category/add_category/' . $work_cate['id'] . '/edit');
        ?>
" title="修改分类信息" > 
															<i class="ace-icon fa fa-pencil bigger-130"></i>
														</a>
                                                        <a class="red delete_rount" rel="<?php 
        echo site_url('admin/category/delete_category/' . $work_cate['id'] . '/new_cates');
        ?>
" href="javascript:void(0)" title="删除分类信息" >
															<i class="ace-icon fa fa-trash-o bigger-130"></i>
														</a>
													</div>													
												</td>
											</tr>
                                            <?php 
        has_child($work_cate['id'], $sub . "&nbsp;&nbsp;");
    }
}