예제 #1
0
function display_child_nodes($parent_id, $level)
{
    global $data, $index;
    $parent_id = $parent_id === NULL ? "NULL" : $parent_id;
    if (isset($index[$parent_id])) {
        foreach ($index[$parent_id] as $id) {
            echo str_repeat("-", $level) . $data[$id]["topic_title"] . "\n";
            display_child_nodes($id, $level + 1);
        }
    }
}
예제 #2
0
    function display_child_nodes($parent_id, $level)
    {
        global $data, $index;
        $parent_id = $parent_id === NULL ? "NULL" : $parent_id;
        if (isset($index[$parent_id])) {
            foreach ($index[$parent_id] as $id) {
                $category = get_queried_object();
                if ($level == 0) {
                    $term_list = wp_get_post_terms(get_the_ID(), 'product_categories');
                    if ($category->parent == $id || $id == $category->term_id || $term_list[0]->parent == $id) {
                        echo '  <li><a class="accordion-link" href="#">' . $data[$id]["name"] . '</a><ul class="accordion-list-content" style="display:block;color:#0076F9;">';
                    } else {
                        echo '  <li><a class="accordion-link" href="#">' . $data[$id]["name"] . '</a><ul class="accordion-list-content">';
                    }
                }
                $permalink = get_term_link($data[$id]["slug"], $data[$id]["taxonomy"]);
                if ($level != 0) {
                    echo "<li>";
                    $terms = get_the_terms($post->ID, $data[$id]["taxonomy"]);
                    if (!empty($terms)) {
                        foreach ($terms as $term) {
                            $termID[] = $term->term_id;
                        }
                        if ($termID[0] == $id) {
                            echo "<a href='" . $permalink . "' style='color:#000;  font-weight: 600;' class='act_cl'>" . $data[$id]["name"] . "</a>";
                        } else {
                            echo "<a href='" . $permalink . "' style='color:#000;  font-weight: 600;' >" . $data[$id]["name"] . "</a>";
                        }
                    } else {
                        echo "<a href='" . $permalink . "' style='color:#000 ; font-weight: 600;'>" . $data[$id]["name"] . "</a>";
                    }
                    $post_lists = get_posts(array('numberposts' => -1, 'post_type' => 'product', 'suppress_filters' => false, 'tax_query' => array(array('taxonomy' => $data[$id]["taxonomy"], 'field' => 'id', 'terms' => $id))));
                    ?>
                    <ul class="post_ul"><?php 
                    if (!empty($post_lists)) {
                        foreach ($post_lists as $list) {
                            ?>
<li><a href="<?php 
                            echo get_permalink($list->ID);
                            ?>
" title="<?php 
                            echo get_the_title($list->ID);
                            ?>
"><?php 
                            echo get_the_title($list->ID);
                            ?>
</a></li><?php 
                        }
                        ?>
                        </ul>
                        <?php 
                    }
                }
                display_child_nodes($id, $level + 1);
                echo "</li>";
                if ($level == 0) {
                    echo "</ul></li>";
                }
            }
        }
    }