有没有办法将 ul 标签添加到输出中?

发布于 2024-12-12 06:14:52 字数 10944 浏览 0 评论 0原文

<?php

  $content = "";

  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    switch(true) {
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday';
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top';
        break;
      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs';
        break;
      default:
        $new_style = 'category-products';
      }
     if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
        // skip if this is for the document box (==3)
      } else {
      $content .= '<li class="' . $new_style . '"><a  href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';

      if ($box_categories_array[$i]['current']) {
        if ($box_categories_array[$i]['has_sub_cat']) {
          $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
        } else {
          $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
        }
      } else {
        $content .= $box_categories_array[$i]['name'];
      }

      if ($box_categories_array[$i]['has_sub_cat']) {
        $content .= CATEGORIES_SEPARATOR;
      }
      $content .= '</a></li>';

      if (SHOW_COUNTS == 'true') {
        if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
        }
      }

      $content .=  "\n";
    }
  }

上面的html输出是这样的: 在此处输入图像描述

现在,我想在输出中添加一些 ul 标签。也就是说,当它位于category-top并且有子类别时。我想让输出像这样。

<li class="category-top"> <a href="#">main category</a>
<ul>
<li class="category-topb"><a href="#">sub category</a></li>
<li class="category-topb"><a href="#">sub category</a></li>
<li class="category-topb"><a href="#">sub category</a></li>
</ul>
</li>

当它没有子类别时,输出如下

  • ...
  • 如何添加ul标签? 谢谢你!

    Array
    (
        [0] => Array
            (
                [top] => true
                [path] => cPath=1
                [name] => Hardware
                [has_sub_cat] => 1
            )
    
        [1] => Array
            (
                [top] => false
                [path] => cPath=1_17
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;CDROM Drives
            )
    
        [2] => Array
            (
                [top] => false
                [path] => cPath=1_4
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Graphics Cards
            )
    
        [3] => Array
            (
                [top] => false
                [path] => cPath=1_8
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Keyboards
            )
    
        [4] => Array
            (
                [top] => false
                [path] => cPath=1_16
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Memory
            )
    
        [5] => Array
            (
                [top] => false
                [path] => cPath=1_9
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Mice
            )
    
        [6] => Array
            (
                [top] => false
                [path] => cPath=1_6
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Monitors
            )
    
        [7] => Array
            (
                [top] => false
                [path] => cPath=1_5
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Printers
            )
    
        [8] => Array
            (
                [top] => false
                [path] => cPath=1_7
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Speakers
            )
    
        [9] => Array
            (
                [top] => true
                [path] => cPath=2
                [name] => Software
                [has_sub_cat] => 1
            )
    
        [10] => Array
            (
                [top] => false
                [path] => cPath=2_19
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Action
            )
    
        [11] => Array
            (
                [top] => false
                [path] => cPath=2_18
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Simulation
            )
    
        [12] => Array
            (
                [top] => false
                [path] => cPath=2_20
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Strategy
            )
    
        [13] => Array
            (
                [top] => true
                [path] => cPath=3
                [name] => DVD Movies
                [has_sub_cat] => 1
            )
    
        [14] => Array
            (
                [top] => false
                [path] => cPath=3_10
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Action
            )
    
        [15] => Array
            (
                [top] => false
                [path] => cPath=3_13
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Cartoons
            )
    
        [16] => Array
            (
                [top] => false
                [path] => cPath=3_12
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Comedy
            )
    
        [17] => Array
            (
                [top] => false
                [path] => cPath=3_15
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Drama
            )
    
        [18] => Array
            (
                [top] => false
                [path] => cPath=3_11
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Science Fiction
            )
    
        [19] => Array
            (
                [top] => false
                [path] => cPath=3_14
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;Thriller
            )
    
        [20] => Array
            (
                [top] => true
                [path] => cPath=21
                [name] => Gift Certificates
            )
    
        [21] => Array
            (
                [top] => true
                [path] => cPath=22
                [name] => Big Linked
            )
    
        [22] => Array
            (
                [top] => true
                [path] => cPath=23
                [name] => Test Examples
            )
    
        [23] => Array
            (
                [top] => true
                [path] => cPath=24
                [name] => Free Call Stuff
            )
    
        [24] => Array
            (
                [top] => true
                [path] => cPath=33
                [name] => A Top Level Cat
                [has_sub_cat] => 1
            )
    
        [25] => Array
            (
                [top] => false
                [path] => cPath=33_34
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;SubLevel 2 A
                [has_sub_cat] => 1
            )
    
        [26] => Array
            (
                [top] => false
                [path] => cPath=33_34_40
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2A1
            )
    
        [27] => Array
            (
                [top] => false
                [path] => cPath=33_34_43
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2A2
            )
    
        [28] => Array
            (
                [top] => false
                [path] => cPath=33_35
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;SubLevel 2 B
                [has_sub_cat] => 1
            )
    
        [29] => Array
            (
                [top] => false
                [path] => cPath=33_35_37
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2B1
            )
    
        [30] => Array
            (
                [top] => false
                [path] => cPath=33_35_38
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2B2
            )
    
        [31] => Array
            (
                [top] => false
                [path] => cPath=33_35_39
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2B3
            )
    
        [32] => Array
            (
                [top] => false
                [path] => cPath=33_36
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;SubLevel 2 C
                [has_sub_cat] => 1
            )
    
        [33] => Array
            (
                [top] => false
                [path] => cPath=33_36_41
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2C1
            )
    
        [34] => Array
            (
                [top] => false
                [path] => cPath=33_36_44
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2C2
            )
    
        [35] => Array
            (
                [top] => false
                [path] => cPath=33_36_42
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Sub Cat 2C3
            )
    
        [36] => Array
            (
                [top] => true
                [path] => cPath=48
                [name] => Sale Percentage
                [has_sub_cat] => 1
            )
    
        [37] => Array
            (
                [top] => false
                [path] => cPath=48_45
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;10% off
            )
    
        [38] => Array
            (
                [top] => false
                [path] => cPath=48_47
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;10% off Attrib
            )
    
        [39] => Array
            (
                [top] => false
                [path] => cPath=48_31
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;10% off Skip
            )
    
        [40] => Array
            (
                [top] => false
                [path] => cPath=48_32
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;10% off Price
            )
    
        [41] => Array
            (
                [top] => true
                [path] => cPath=49
                [name] => Sale Deduction
                [has_sub_cat] => 1
            )
    
        [42] => Array
            (
                [top] => false
                [path] => cPath=49_27
                [name] => &nbsp;&nbsp;&nbsp;&nbsp;$5.00 off
            )
    ......
    
    <?php
    
      $content = "";
    
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
         if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            // skip if this is for the document box (==3)
          } else {
          $content .= '<li class="' . $new_style . '"><a  href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
    
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
    
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
          $content .= '</a></li>';
    
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
    
          $content .=  "\n";
        }
      }
    

    the above html output like this:
    enter image description here

    Now, I want to add some ul label into the output. Namely, when it's category-top and have sub category. I want to make the output like this.

    <li class="category-top"> <a href="#">main category</a>
    <ul>
    <li class="category-topb"><a href="#">sub category</a></li>
    <li class="category-topb"><a href="#">sub category</a></li>
    <li class="category-topb"><a href="#">sub category</a></li>
    </ul>
    </li>
    

    When it doesn't have sub category the output is like this <li class="category-top"> <a href="#">...</a></li>.

    How to add the ul label?
    Thank you!

    Array
    (
        [0] => Array
            (
                [top] => true
                [path] => cPath=1
                [name] => Hardware
                [has_sub_cat] => 1
            )
    
        [1] => Array
            (
                [top] => false
                [path] => cPath=1_17
                [name] =>     CDROM Drives
            )
    
        [2] => Array
            (
                [top] => false
                [path] => cPath=1_4
                [name] =>     Graphics Cards
            )
    
        [3] => Array
            (
                [top] => false
                [path] => cPath=1_8
                [name] =>     Keyboards
            )
    
        [4] => Array
            (
                [top] => false
                [path] => cPath=1_16
                [name] =>     Memory
            )
    
        [5] => Array
            (
                [top] => false
                [path] => cPath=1_9
                [name] =>     Mice
            )
    
        [6] => Array
            (
                [top] => false
                [path] => cPath=1_6
                [name] =>     Monitors
            )
    
        [7] => Array
            (
                [top] => false
                [path] => cPath=1_5
                [name] =>     Printers
            )
    
        [8] => Array
            (
                [top] => false
                [path] => cPath=1_7
                [name] =>     Speakers
            )
    
        [9] => Array
            (
                [top] => true
                [path] => cPath=2
                [name] => Software
                [has_sub_cat] => 1
            )
    
        [10] => Array
            (
                [top] => false
                [path] => cPath=2_19
                [name] =>     Action
            )
    
        [11] => Array
            (
                [top] => false
                [path] => cPath=2_18
                [name] =>     Simulation
            )
    
        [12] => Array
            (
                [top] => false
                [path] => cPath=2_20
                [name] =>     Strategy
            )
    
        [13] => Array
            (
                [top] => true
                [path] => cPath=3
                [name] => DVD Movies
                [has_sub_cat] => 1
            )
    
        [14] => Array
            (
                [top] => false
                [path] => cPath=3_10
                [name] =>     Action
            )
    
        [15] => Array
            (
                [top] => false
                [path] => cPath=3_13
                [name] =>     Cartoons
            )
    
        [16] => Array
            (
                [top] => false
                [path] => cPath=3_12
                [name] =>     Comedy
            )
    
        [17] => Array
            (
                [top] => false
                [path] => cPath=3_15
                [name] =>     Drama
            )
    
        [18] => Array
            (
                [top] => false
                [path] => cPath=3_11
                [name] =>     Science Fiction
            )
    
        [19] => Array
            (
                [top] => false
                [path] => cPath=3_14
                [name] =>     Thriller
            )
    
        [20] => Array
            (
                [top] => true
                [path] => cPath=21
                [name] => Gift Certificates
            )
    
        [21] => Array
            (
                [top] => true
                [path] => cPath=22
                [name] => Big Linked
            )
    
        [22] => Array
            (
                [top] => true
                [path] => cPath=23
                [name] => Test Examples
            )
    
        [23] => Array
            (
                [top] => true
                [path] => cPath=24
                [name] => Free Call Stuff
            )
    
        [24] => Array
            (
                [top] => true
                [path] => cPath=33
                [name] => A Top Level Cat
                [has_sub_cat] => 1
            )
    
        [25] => Array
            (
                [top] => false
                [path] => cPath=33_34
                [name] =>     SubLevel 2 A
                [has_sub_cat] => 1
            )
    
        [26] => Array
            (
                [top] => false
                [path] => cPath=33_34_40
                [name] =>       Sub Sub Cat 2A1
            )
    
        [27] => Array
            (
                [top] => false
                [path] => cPath=33_34_43
                [name] =>       Sub Sub Cat 2A2
            )
    
        [28] => Array
            (
                [top] => false
                [path] => cPath=33_35
                [name] =>     SubLevel 2 B
                [has_sub_cat] => 1
            )
    
        [29] => Array
            (
                [top] => false
                [path] => cPath=33_35_37
                [name] =>       Sub Sub Cat 2B1
            )
    
        [30] => Array
            (
                [top] => false
                [path] => cPath=33_35_38
                [name] =>       Sub Sub Cat 2B2
            )
    
        [31] => Array
            (
                [top] => false
                [path] => cPath=33_35_39
                [name] =>       Sub Sub Cat 2B3
            )
    
        [32] => Array
            (
                [top] => false
                [path] => cPath=33_36
                [name] =>     SubLevel 2 C
                [has_sub_cat] => 1
            )
    
        [33] => Array
            (
                [top] => false
                [path] => cPath=33_36_41
                [name] =>       Sub Sub Cat 2C1
            )
    
        [34] => Array
            (
                [top] => false
                [path] => cPath=33_36_44
                [name] =>       Sub Sub Cat 2C2
            )
    
        [35] => Array
            (
                [top] => false
                [path] => cPath=33_36_42
                [name] =>       Sub Sub Cat 2C3
            )
    
        [36] => Array
            (
                [top] => true
                [path] => cPath=48
                [name] => Sale Percentage
                [has_sub_cat] => 1
            )
    
        [37] => Array
            (
                [top] => false
                [path] => cPath=48_45
                [name] =>     10% off
            )
    
        [38] => Array
            (
                [top] => false
                [path] => cPath=48_47
                [name] =>     10% off Attrib
            )
    
        [39] => Array
            (
                [top] => false
                [path] => cPath=48_31
                [name] =>     10% off Skip
            )
    
        [40] => Array
            (
                [top] => false
                [path] => cPath=48_32
                [name] =>     10% off Price
            )
    
        [41] => Array
            (
                [top] => true
                [path] => cPath=49
                [name] => Sale Deduction
                [has_sub_cat] => 1
            )
    
        [42] => Array
            (
                [top] => false
                [path] => cPath=49_27
                [name] =>     $5.00 off
            )
    ......
    

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(3

    怪异←思 2024-12-19 06:14:52
    <?php
    
      $content = "";
    
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
         if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            // skip if this is for the document box (==3)
          } else {
          $content .= '<li class="' . $new_style . '"><a  href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
    
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
    
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
    
          /* ADDED THIS */
          $content .= '</a>';
          if($i+1 < sizeof($box_categories_array) && $box_categories_array[$i+1]['has_sub_cat'] && $new_style == 'category-top') // new UL
          {
            $content .= '<ul>';
          }
          elseif(($i+1 < sizeof($box_categories_array) && !$box_categories_array[$i+1]['has_sub_cat'] && $new_style == 'category-subs') || $i+1 == sizeof($box_categories_array)) // new UL
          {
            $content .= '</ul></li>';
          }
          else
            $content .= '</li>';
          /* UNTIL HERE */
    
    
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
    
          $content .=  "\n";
        }
      }
    
    <?php
    
      $content = "";
    
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
         if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            // skip if this is for the document box (==3)
          } else {
          $content .= '<li class="' . $new_style . '"><a  href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
    
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
    
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
    
          /* ADDED THIS */
          $content .= '</a>';
          if($i+1 < sizeof($box_categories_array) && $box_categories_array[$i+1]['has_sub_cat'] && $new_style == 'category-top') // new UL
          {
            $content .= '<ul>';
          }
          elseif(($i+1 < sizeof($box_categories_array) && !$box_categories_array[$i+1]['has_sub_cat'] && $new_style == 'category-subs') || $i+1 == sizeof($box_categories_array)) // new UL
          {
            $content .= '</ul></li>';
          }
          else
            $content .= '</li>';
          /* UNTIL HERE */
    
    
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
    
          $content .=  "\n";
        }
      }
    
    墨落成白 2024-12-19 06:14:52
    <?php
    
      $content = "";
    
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
         if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            // skip if this is for the document box (==3)
          } else {
          $content .= '<li class="' . $new_style . '"><a  href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
    
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
    
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
    
          $content .= '</a>';
          if($i+1 < sizeof($box_categories_array) && !$box_categories_array[$i+1]['top'] && $box_categories_array[$i]['top']) // new UL
          {
            $content .= '<ul>';
          }
          elseif(($i+1 < sizeof($box_categories_array) && $box_categories_array[$i+1]['top'] && !$box_categories_array[$i]['top']) || $i+1 == sizeof($box_categories_array)) // new UL
          {
            $content .= '</ul></li>';
          }
          else
            $content .= '</li>';
    
    
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
    
          $content .=  "\n";
        }
      }
    
    <?php
    
      $content = "";
    
      $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
      for ($i=0;$i<sizeof($box_categories_array);$i++) {
        switch(true) {
    // to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
    // uncomment the select below and set the cPath=3 to the cPath= your_categories_id
    // many variations of this can be done
    //      case ($box_categories_array[$i]['path'] == 'cPath=3'):
    //        $new_style = 'category-holiday';
    //        break;
          case ($box_categories_array[$i]['top'] == 'true'):
            $new_style = 'category-top';
            break;
          case ($box_categories_array[$i]['has_sub_cat']):
            $new_style = 'category-subs';
            break;
          default:
            $new_style = 'category-products';
          }
         if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            // skip if this is for the document box (==3)
          } else {
          $content .= '<li class="' . $new_style . '"><a  href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
    
          if ($box_categories_array[$i]['current']) {
            if ($box_categories_array[$i]['has_sub_cat']) {
              $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
            } else {
              $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
            }
          } else {
            $content .= $box_categories_array[$i]['name'];
          }
    
          if ($box_categories_array[$i]['has_sub_cat']) {
            $content .= CATEGORIES_SEPARATOR;
          }
    
          $content .= '</a>';
          if($i+1 < sizeof($box_categories_array) && !$box_categories_array[$i+1]['top'] && $box_categories_array[$i]['top']) // new UL
          {
            $content .= '<ul>';
          }
          elseif(($i+1 < sizeof($box_categories_array) && $box_categories_array[$i+1]['top'] && !$box_categories_array[$i]['top']) || $i+1 == sizeof($box_categories_array)) // new UL
          {
            $content .= '</ul></li>';
          }
          else
            $content .= '</li>';
    
    
          if (SHOW_COUNTS == 'true') {
            if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
              $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
            }
          }
    
          $content .=  "\n";
        }
      }
    
    谁与争疯 2024-12-19 06:14:52

    输出中仍然没有任何 ul

    echo sizeof($box_categories_array); 显示 58

    echo $box_categories_array[2]['top'] 显示 false

    在此处输入图像描述

    print_r($box_categories_array) results:
    <pre>Array
    (
        [0] => Array
            (
                [top] => true
                [path] => cPath=1
                [name] => Hardware
                [has_sub_cat] => 1
            )
    
        [1] => Array
            (
                [top] => false
                [path] => cPath=1_17
                [name] =>     CDROM Drives
            )
    
        [2] => Array
            (
                [top] => false
                [path] => cPath=1_4
                [name] =>     Graphics Cards
            )
    
        [3] => Array
            (
                [top] => false
                [path] => cPath=1_8
                [name] =>     Keyboards
            )
    
        [4] => Array
            (
                [top] => false
                [path] => cPath=1_16
                [name] =>     Memory
            )
    
        [5] => Array
            (
                [top] => false
                [path] => cPath=1_9
                [name] =>     Mice
            )
    
        [6] => Array
            (
                [top] => false
                [path] => cPath=1_6
                [name] =>     Monitors
            )
    
        [7] => Array
            (
                [top] => false
                [path] => cPath=1_5
                [name] =>     Printers
            )
    
        [8] => Array
            (
                [top] => false
                [path] => cPath=1_7
                [name] =>     Speakers
            )
    
        [9] => Array
            (
                [top] => true
                [path] => cPath=2
                [name] => Software
                [has_sub_cat] => 1
            )
    
        [10] => Array
            (
                [top] => false
                [path] => cPath=2_19
                [name] =>     Action
            )
    
        [11] => Array
            (
                [top] => false
                [path] => cPath=2_18
                [name] =>     Simulation
            )
    
        [12] => Array
            (
                [top] => false
                [path] => cPath=2_20
                [name] =>     Strategy
            )
    
        [13] => Array
            (
                [top] => true
                [path] => cPath=3
                [name] => DVD Movies
                [has_sub_cat] => 1
            )
    
        [14] => Array
            (
                [top] => false
                [path] => cPath=3_10
                [name] =>     Action
            )
    
        [15] => Array
            (
                [top] => false
                [path] => cPath=3_13
                [name] =>     Cartoons
            )
    
        [16] => Array
            (
                [top] => false
                [path] => cPath=3_12
                [name] =>     Comedy
            )
    
        [17] => Array
            (
                [top] => false
                [path] => cPath=3_15
                [name] =>     Drama
            )
    
        [18] => Array
            (
                [top] => false
                [path] => cPath=3_11
                [name] =>     Science Fiction
            )
    
        [19] => Array
            (
                [top] => false
                [path] => cPath=3_14
                [name] =>     Thriller
            )
    
        [20] => Array
            (
                [top] => true
                [path] => cPath=21
                [name] => Gift Certificates
            )
    
        [21] => Array
            (
                [top] => true
                [path] => cPath=22
                [name] => Big Linked
            )
    
        [22] => Array
            (
                [top] => true
                [path] => cPath=23
                [name] => Test Examples
            )
    
        [23] => Array
            (
                [top] => true
                [path] => cPath=24
                [name] => Free Call Stuff
            )
    
        [24] => Array
            (
                [top] => true
                [path] => cPath=33
                [name] => A Top Level Cat
                [has_sub_cat] => 1
            )
    
        [25] => Array
            (
                [top] => false
                [path] => cPath=33_34
                [name] =>     SubLevel 2 A
                [has_sub_cat] => 1
            )
    
        [26] => Array
            (
                [top] => false
                [path] => cPath=33_34_40
                [name] =>       Sub Sub Cat 2A1
            )
    
        [27] => Array
            (
                [top] => false
                [path] => cPath=33_34_43
                [name] =>       Sub Sub Cat 2A2
            )
    
        [28] => Array
            (
                [top] => false
                [path] => cPath=33_35
                [name] =>     SubLevel 2 B
                [has_sub_cat] => 1
            )
    
        [29] => Array
            (
                [top] => false
                [path] => cPath=33_35_37
                [name] =>       Sub Sub Cat 2B1
            )
    
        [30] => Array
            (
                [top] => false
                [path] => cPath=33_35_38
                [name] =>       Sub Sub Cat 2B2
            )
    
        [31] => Array
            (
                [top] => false
                [path] => cPath=33_35_39
                [name] =>       Sub Sub Cat 2B3
            )
    
        [32] => Array
            (
                [top] => false
                [path] => cPath=33_36
                [name] =>     SubLevel 2 C
                [has_sub_cat] => 1
            )
    
        [33] => Array
            (
                [top] => false
                [path] => cPath=33_36_41
                [name] =>       Sub Sub Cat 2C1
            )
    
        [34] => Array
            (
                [top] => false
                [path] => cPath=33_36_44
                [name] =>       Sub Sub Cat 2C2
            )
    
        [35] => Array
            (
                [top] => false
                [path] => cPath=33_36_42
                [name] =>       Sub Sub Cat 2C3
            )
    
        [36] => Array
            (
                [top] => true
                [path] => cPath=48
                [name] => Sale Percentage
                [has_sub_cat] => 1
            )
    
        [37] => Array
            (
                [top] => false
                [path] => cPath=48_45
                [name] =>     10% off
            )
    
        [38] => Array
            (
                [top] => false
                [path] => cPath=48_47
                [name] =>     10% off Attrib
            )
    
        [39] => Array
            (
                [top] => false
                [path] => cPath=48_31
                [name] =>     10% off Skip
            )
    
        [40] => Array
            (
                [top] => false
                [path] => cPath=48_32
                [name] =>     10% off Price
            )
    
        [41] => Array
            (
                [top] => true
                [path] => cPath=49
                [name] => Sale Deduction
                [has_sub_cat] => 1
            )
    
        [42] => Array
            (
                [top] => false
                [path] => cPath=49_27
                [name] =>     $5.00 off
            )
    
        [43] => Array
            (
                [top] => false
                [path] => cPath=49_52
                [name] =>     $5.00 off Skip
            )
    
        [44] => Array
            (
                [top] => true
                [path] => cPath=50
                [name] => Sale New Price
                [has_sub_cat] => 1
            )
    
        [45] => Array
            (
                [top] => false
                [path] => cPath=50_46
                [name] =>     Set $100
            )
    
        [46] => Array
            (
                [top] => false
                [path] => cPath=50_51
                [name] =>     Set $100 Skip
            )
    
        [47] => Array
            (
                [top] => true
                [path] => cPath=53
                [name] => Big Unlinked
            )
    
        [48] => Array
            (
                [top] => true
                [path] => cPath=54
                [name] => New v1.2
                [has_sub_cat] => 1
            )
    
        [49] => Array
            (
                [top] => false
                [path] => cPath=54_56
                [name] =>     Attributes
            )
    
        [50] => Array
            (
                [top] => false
                [path] => cPath=54_55
                [name] =>     Discount Qty
            )
    
        [51] => Array
            (
                [top] => false
                [path] => cPath=54_60
                [name] =>     Downloads
            )
    
        [52] => Array
            (
                [top] => false
                [path] => cPath=54_57
                [name] =>     Text Pricing
            )
    
        [53] => Array
            (
                [top] => false
                [path] => cPath=54_61
                [name] =>     Real
            )
    
        [54] => Array
            (
                [top] => false
                [path] => cPath=54_58
                [name] =>     Real Sale
            )
    
        [55] => Array
            (
                [top] => true
                [path] => cPath=62
                [name] => Music
            )
    
        [56] => Array
            (
                [top] => true
                [path] => cPath=63
                [name] => Documents
            )
    
        [57] => Array
            (
                [top] => true
                [path] => cPath=64
                [name] => Mixed Product Types
            )
    
    )
    

    There is still no any ul in the output.

    echo sizeof($box_categories_array); shows 58

    echo $box_categories_array[2]['top'] shows false

    enter image description here

    print_r($box_categories_array) results:
    <pre>Array
    (
        [0] => Array
            (
                [top] => true
                [path] => cPath=1
                [name] => Hardware
                [has_sub_cat] => 1
            )
    
        [1] => Array
            (
                [top] => false
                [path] => cPath=1_17
                [name] =>     CDROM Drives
            )
    
        [2] => Array
            (
                [top] => false
                [path] => cPath=1_4
                [name] =>     Graphics Cards
            )
    
        [3] => Array
            (
                [top] => false
                [path] => cPath=1_8
                [name] =>     Keyboards
            )
    
        [4] => Array
            (
                [top] => false
                [path] => cPath=1_16
                [name] =>     Memory
            )
    
        [5] => Array
            (
                [top] => false
                [path] => cPath=1_9
                [name] =>     Mice
            )
    
        [6] => Array
            (
                [top] => false
                [path] => cPath=1_6
                [name] =>     Monitors
            )
    
        [7] => Array
            (
                [top] => false
                [path] => cPath=1_5
                [name] =>     Printers
            )
    
        [8] => Array
            (
                [top] => false
                [path] => cPath=1_7
                [name] =>     Speakers
            )
    
        [9] => Array
            (
                [top] => true
                [path] => cPath=2
                [name] => Software
                [has_sub_cat] => 1
            )
    
        [10] => Array
            (
                [top] => false
                [path] => cPath=2_19
                [name] =>     Action
            )
    
        [11] => Array
            (
                [top] => false
                [path] => cPath=2_18
                [name] =>     Simulation
            )
    
        [12] => Array
            (
                [top] => false
                [path] => cPath=2_20
                [name] =>     Strategy
            )
    
        [13] => Array
            (
                [top] => true
                [path] => cPath=3
                [name] => DVD Movies
                [has_sub_cat] => 1
            )
    
        [14] => Array
            (
                [top] => false
                [path] => cPath=3_10
                [name] =>     Action
            )
    
        [15] => Array
            (
                [top] => false
                [path] => cPath=3_13
                [name] =>     Cartoons
            )
    
        [16] => Array
            (
                [top] => false
                [path] => cPath=3_12
                [name] =>     Comedy
            )
    
        [17] => Array
            (
                [top] => false
                [path] => cPath=3_15
                [name] =>     Drama
            )
    
        [18] => Array
            (
                [top] => false
                [path] => cPath=3_11
                [name] =>     Science Fiction
            )
    
        [19] => Array
            (
                [top] => false
                [path] => cPath=3_14
                [name] =>     Thriller
            )
    
        [20] => Array
            (
                [top] => true
                [path] => cPath=21
                [name] => Gift Certificates
            )
    
        [21] => Array
            (
                [top] => true
                [path] => cPath=22
                [name] => Big Linked
            )
    
        [22] => Array
            (
                [top] => true
                [path] => cPath=23
                [name] => Test Examples
            )
    
        [23] => Array
            (
                [top] => true
                [path] => cPath=24
                [name] => Free Call Stuff
            )
    
        [24] => Array
            (
                [top] => true
                [path] => cPath=33
                [name] => A Top Level Cat
                [has_sub_cat] => 1
            )
    
        [25] => Array
            (
                [top] => false
                [path] => cPath=33_34
                [name] =>     SubLevel 2 A
                [has_sub_cat] => 1
            )
    
        [26] => Array
            (
                [top] => false
                [path] => cPath=33_34_40
                [name] =>       Sub Sub Cat 2A1
            )
    
        [27] => Array
            (
                [top] => false
                [path] => cPath=33_34_43
                [name] =>       Sub Sub Cat 2A2
            )
    
        [28] => Array
            (
                [top] => false
                [path] => cPath=33_35
                [name] =>     SubLevel 2 B
                [has_sub_cat] => 1
            )
    
        [29] => Array
            (
                [top] => false
                [path] => cPath=33_35_37
                [name] =>       Sub Sub Cat 2B1
            )
    
        [30] => Array
            (
                [top] => false
                [path] => cPath=33_35_38
                [name] =>       Sub Sub Cat 2B2
            )
    
        [31] => Array
            (
                [top] => false
                [path] => cPath=33_35_39
                [name] =>       Sub Sub Cat 2B3
            )
    
        [32] => Array
            (
                [top] => false
                [path] => cPath=33_36
                [name] =>     SubLevel 2 C
                [has_sub_cat] => 1
            )
    
        [33] => Array
            (
                [top] => false
                [path] => cPath=33_36_41
                [name] =>       Sub Sub Cat 2C1
            )
    
        [34] => Array
            (
                [top] => false
                [path] => cPath=33_36_44
                [name] =>       Sub Sub Cat 2C2
            )
    
        [35] => Array
            (
                [top] => false
                [path] => cPath=33_36_42
                [name] =>       Sub Sub Cat 2C3
            )
    
        [36] => Array
            (
                [top] => true
                [path] => cPath=48
                [name] => Sale Percentage
                [has_sub_cat] => 1
            )
    
        [37] => Array
            (
                [top] => false
                [path] => cPath=48_45
                [name] =>     10% off
            )
    
        [38] => Array
            (
                [top] => false
                [path] => cPath=48_47
                [name] =>     10% off Attrib
            )
    
        [39] => Array
            (
                [top] => false
                [path] => cPath=48_31
                [name] =>     10% off Skip
            )
    
        [40] => Array
            (
                [top] => false
                [path] => cPath=48_32
                [name] =>     10% off Price
            )
    
        [41] => Array
            (
                [top] => true
                [path] => cPath=49
                [name] => Sale Deduction
                [has_sub_cat] => 1
            )
    
        [42] => Array
            (
                [top] => false
                [path] => cPath=49_27
                [name] =>     $5.00 off
            )
    
        [43] => Array
            (
                [top] => false
                [path] => cPath=49_52
                [name] =>     $5.00 off Skip
            )
    
        [44] => Array
            (
                [top] => true
                [path] => cPath=50
                [name] => Sale New Price
                [has_sub_cat] => 1
            )
    
        [45] => Array
            (
                [top] => false
                [path] => cPath=50_46
                [name] =>     Set $100
            )
    
        [46] => Array
            (
                [top] => false
                [path] => cPath=50_51
                [name] =>     Set $100 Skip
            )
    
        [47] => Array
            (
                [top] => true
                [path] => cPath=53
                [name] => Big Unlinked
            )
    
        [48] => Array
            (
                [top] => true
                [path] => cPath=54
                [name] => New v1.2
                [has_sub_cat] => 1
            )
    
        [49] => Array
            (
                [top] => false
                [path] => cPath=54_56
                [name] =>     Attributes
            )
    
        [50] => Array
            (
                [top] => false
                [path] => cPath=54_55
                [name] =>     Discount Qty
            )
    
        [51] => Array
            (
                [top] => false
                [path] => cPath=54_60
                [name] =>     Downloads
            )
    
        [52] => Array
            (
                [top] => false
                [path] => cPath=54_57
                [name] =>     Text Pricing
            )
    
        [53] => Array
            (
                [top] => false
                [path] => cPath=54_61
                [name] =>     Real
            )
    
        [54] => Array
            (
                [top] => false
                [path] => cPath=54_58
                [name] =>     Real Sale
            )
    
        [55] => Array
            (
                [top] => true
                [path] => cPath=62
                [name] => Music
            )
    
        [56] => Array
            (
                [top] => true
                [path] => cPath=63
                [name] => Documents
            )
    
        [57] => Array
            (
                [top] => true
                [path] => cPath=64
                [name] => Mixed Product Types
            )
    
    )
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文