找回密码
 立即注册

typecho隐藏子分类或折叠子分类

2022-7-23 22:21:28 · 站长社区
若仅仅只想隐藏子分类
  1. <?php
  2. $obj = $this->widget('Widget_Metas_Category_List');
  3. if($obj->have()){
  4.     while($obj->next()){
  5.      if ($obj->levels === 0){
  6.         echo '<li><a href="'.$obj->permalink.'">'.$obj->name.'</a></li>';
  7.         }
  8.     }
  9. }
  10. ?>
复制代码
子分类折叠,当鼠标移动到父分类后会显示出父分类下面的子分类
  1. <?php
  2. $categories = $this->widget('Widget_Metas_Category_List');
  3. while($categories->next()){
  4. if ($categories->levels === 0){
  5.     $html = '<li><div class="category-parent">';
  6.     $html .= '<a href="'.$categories->permalink.'">'.$categories->name.'</a>';
  7.     echo $html;
  8.     $children = $categories->getAllChildren($categories->mid);
  9.     if (!empty($children)){
  10.     $childCategoryHtml = '<div class="category-child"><ul class="widget-tile">';
  11.     foreach ($children as $mid){
  12.         $child = $categories->getCategory($mid);
  13.         $childCategoryHtml .= '<li><a href="'.$child['permalink'].'">'.$child['name'].'</a></li>';
  14.     }
  15.     $childCategoryHtml  .= '</ul></div>';
  16.     echo $childCategoryHtml;
  17.     echo "</div></li>";
  18.     }
  19. }
  20. }
  21. ?>



  22. <style type="text/css">
  23. .category-parent .category-child {display: none;position: absolute;background: #cd9a9a;}
  24. .category-parent:hover .category-child {display: block;}
  25. </style>
复制代码


全部评论 0

若仅仅只想隐藏子分类
  1. <?php
  2. $obj = $this->widget('Widget_Metas_Category_List');
  3. if($obj->have()){
  4.     while($obj->next()){
  5.      if ($obj->levels === 0){
  6.         echo '<li><a href="'.$obj->permalink.'">'.$obj->name.'</a></li>';
  7.         }
  8.     }
  9. }
  10. ?>
复制代码
子分类折叠,当鼠标移动到父分类后会显示出父分类下面的子分类
  1. <?php
  2. $categories = $this->widget('Widget_Metas_Category_List');
  3. while($categories->next()){
  4. if ($categories->levels === 0){
  5.     $html = '<li><div class="category-parent">';
  6.     $html .= '<a href="'.$categories->permalink.'">'.$categories->name.'</a>';
  7.     echo $html;
  8.     $children = $categories->getAllChildren($categories->mid);
  9.     if (!empty($children)){
  10.     $childCategoryHtml = '<div class="category-child"><ul class="widget-tile">';
  11.     foreach ($children as $mid){
  12.         $child = $categories->getCategory($mid);
  13.         $childCategoryHtml .= '<li><a href="'.$child['permalink'].'">'.$child['name'].'</a></li>';
  14.     }
  15.     $childCategoryHtml  .= '</ul></div>';
  16.     echo $childCategoryHtml;
  17.     echo "</div></li>";
  18.     }
  19. }
  20. }
  21. ?>



  22. <style type="text/css">
  23. .category-parent .category-child {display: none;position: absolute;background: #cd9a9a;}
  24. .category-parent:hover .category-child {display: block;}
  25. </style>
复制代码


热门推荐
您需要登录后才可以回帖 立即登录
说说你的想法......
0
0
0
返回顶部