Advertisement
Guest User

Untitled

a guest
Dec 20th, 2019
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <?php
  2. //$message = "Started";
  3. //echo "<script type='text/javascript'>alert('$message');</script>";
  4. include 'wp-load.php';
  5.  
  6. $thearray = [];
  7. $terms = get_terms("pa_mymelp");
  8. foreach ( $terms as $term ) {
  9. $categories = $term->name;
  10. array_push($thearray, $categories);
  11. }
  12.  
  13. $categoryLines = $thearray;
  14.  
  15. function buildCategoryTree($categoryLines, $separator) {
  16. $catTree = array();
  17. foreach ($categoryLines as $catLine) {
  18. $path = explode($separator, $catLine);
  19. $node = & $catTree;
  20. foreach ($path as $cat) {
  21. $cat = trim($cat);
  22. if (!isset($node[$cat])) {
  23. $node[$cat] = array();
  24. }
  25. $node = & $node[$cat];
  26. }
  27. }
  28. return $catTree;
  29. }
  30.  
  31. function displayCategoryTree($categoryTree, $indent = '') {
  32. foreach ($categoryTree as $node => $children) {
  33. echo $indent . $node . "\n";
  34. displayCategoryTree($children, $indent . '|- ');
  35. }
  36. }
  37.  
  38. $categoryTree = buildCategoryTree($categoryLines, '/');
  39.  
  40. function displayHtmlCategoryTree($categoryTree, $id = null, $pathSeparator = '/', $parents = '', $display = 'block') {
  41. if (empty($categoryTree)) return '';
  42.  
  43. $str = '<ul' . (!empty($id) ? ' id="'.$id.'"' : '') . '>';
  44. foreach ($categoryTree as $node => $children) {
  45. $currentPath = $parents . (empty($parents) ? '' : $pathSeparator) . $node;
  46. $thelink = '';
  47. $opener = 0;
  48. if (substr_count($currentPath, '/')==5){
  49. $patterns = array(" ", "/", ".");
  50. $thelink = 'http://caap.co.nz/?pa_mymelp=' . strtolower(str_replace($patterns, '-', $currentPath));
  51. $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>' .
  52. /*displayHtmlCategoryTree($children, null, $pathSeparator, $currentPath) .
  53. */'</li>';}
  54. else
  55. {
  56. $cat = [];
  57.  
  58. if (isset($_POST['catID'])){
  59. $cat = $_POST['catID'];
  60. }
  61.  
  62. $str .= '<li id="' . $currentPath . '-li" style="display:' . $display . ';"title="' . $currentPath . '">' . '<input value="0" class="first" type="checkbox" id="' . $currentPath . '">' . '<label for="' . $currentPath . '">' . $node . '</label>';
  63.  
  64. if(in_array($currentPath, $cat)){$str.=displayHtmlCategoryTree($children, $currentPath, $pathSeparator, $currentPath, 'block');}
  65.  
  66.  
  67. }
  68.  
  69.  
  70. }
  71.  
  72. $str .= '</li></ul>';
  73. return $str;
  74. }
  75. echo displayHtmlCategoryTree($categoryTree, "CategoryTree", '/');
  76. //return $tested;
  77. //echo 'Hi There!'
  78.  
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement