Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $thearray = [];
- $terms = get_terms("pa_mymelp");
- foreach ( $terms as $term ) {
- $categories = $term->name;
- array_push($thearray, $categories);
- }
- $categoryLines = $thearray;
- function buildCategoryTree($categoryLines, $separator) {
- $catTree = array();
- foreach ($categoryLines as $catLine) {
- $path = explode($separator, $catLine);
- $node = & $catTree;
- foreach ($path as $cat) {
- $cat = trim($cat);
- if (!isset($node[$cat])) {
- $node[$cat] = array();
- }
- $node = & $node[$cat];
- }
- }
- return $catTree;
- }
- function displayCategoryTree($categoryTree, $indent = '') {
- foreach ($categoryTree as $node => $children) {
- echo $indent . $node . "\n";
- displayCategoryTree($children, $indent . '|- ');
- }
- }
- $categoryTree = buildCategoryTree($categoryLines, '/');
- function displayHtmlCategoryTree($categoryTree, $id = null, $pathSeparator = '/', $parents = '') {
- if (empty($categoryTree)) return '';
- $str = '<ul' . (!empty($id) ? ' id="'.$id.'"' : '') . '>';
- foreach ($categoryTree as $node => $children) {
- $currentPath = $parents . (empty($parents) ? '' : $pathSeparator) . $node;
- $thelink = '';
- $opener = 0;
- if (substr_count($currentPath, '/')==5){
- $patterns = array(" ", "/", ".");
- $thelink = 'http://caap.co.nz/?pa_mymelp=' . strtolower(str_replace($patterns, '-', $currentPath));
- $str .= '<li title="' . $currentPath . '">' . '<input class="first" name="' . $currentPath . '" type="checkbox" id="' . $currentPath . '">' . '<label for="' . $currentPath . '">' . '<a href="' . $thelink .'">' . $node . '</a></label>' .
- /*displayHtmlCategoryTree($children, null, $pathSeparator, $currentPath) .
- */'</li>';}
- else
- {$str .= '<li title="' . $currentPath . '">' . '<input class="first" name="' . $currentPath . '" type="checkbox" id="' . $currentPath . '">' . '<label for="' . $currentPath . '">' . $node . '</label>';
- $str.=displayHtmlCategoryTree($children, null, $pathSeparator, $currentPath);
- }
- }
- $str .= '</li></ul>';
- return $str;
- }
- echo displayHtmlCategoryTree($categoryTree, "CategoryTree", '/');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement