Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$message = "Started";
- //echo "<script type='text/javascript'>alert('$message');</script>";
- include 'wp-load.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 = '', $display = 'block') {
- 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 id="' . $currentPath . '-li" title="' . $currentPath . '">' . '<input value ="0" class="first" type="checkbox" id="' . $currentPath . '">' . '<label for="' . $currentPath . '">' . '<a href="' . $thelink .'">' . $node . '</a></label>' .
- /*displayHtmlCategoryTree($children, null, $pathSeparator, $currentPath) .
- */'</li>';}
- else
- {
- $cat = [];
- if (isset($_POST['catID'])){
- $cat = $_POST['catID'];
- }
- $str .= '<li id="' . $currentPath . '-li" style="display:' . $display . ';"title="' . $currentPath . '">' . '<input value="0" class="first" type="checkbox" id="' . $currentPath . '">' . '<label for="' . $currentPath . '">' . $node . '</label>';
- if(in_array($currentPath, $cat)){$str.=displayHtmlCategoryTree($children, $currentPath, $pathSeparator, $currentPath, 'block');}
- }
- }
- $str .= '</li></ul>';
- return $str;
- }
- echo displayHtmlCategoryTree($categoryTree, "CategoryTree", '/');
- //return $tested;
- //echo 'Hi There!'
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement