首頁 >後端開發 >php教程 >求助修改typecho分类输出的样式

求助修改typecho分类输出的样式

WBOY
WBOY原創
2016-06-06 20:42:301065瀏覽

原本默认分类输出后样式

<code><?php $this->widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list'); ?>

<ul class="widget-list">
<li class="category-level-0 category-parent">
<a href="">产品</a>
<ul class="widget-list">
  <li class="category-level-1 category-child category-level-odd"><a href="">产品1000</a></li>
  <li class="category-level-1 category-child category-level-odd"><a href="">产品2000</a></li>
</ul>
</li>
<li class="category-level-0 category-parent">
<a href="">新闻</a>
<ul class="widget-list">
  <li class="category-level-1 category-child category-level-odd"><a href="">新闻1</a></li>
  <li class="category-level-1 category-child category-level-odd"><a href="">新闻2</a></li>
</ul>
</li>
</ul>
</code>

在网上找到一个输出全部为[a href]的方法

<code>    <?php $this->widget('Widget_Metas_Category_List')->to($category); ?>
    <?php while ($category->next()): ?>
    <a href="<?php%20%24category->permalink();%20?>"><?php $category->name(); ?></a>
    <?php endwhile; ?>
</code>

我想输出全部为[a href]添加相应class 应该怎么写呢

<code><a class="category-level-0 category-parent" href="">产品</a>
<a class="category-level-1 category-child category-level-odd" href="">产品1000</a>
<a class="category-level-1 category-child category-level-odd" href="">产品2000</a>
<a class="category-level-0 category-parent" href="">新闻</a>
<a class="category-level-1 category-child category-level-odd" href="">新闻1</a>
<a class="category-level-1 category-child category-level-odd" href="">新闻2</a>
</code>

回复内容:

原本默认分类输出后样式

<code><?php $this->widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list'); ?>

<ul class="widget-list">
<li class="category-level-0 category-parent">
<a href="">产品</a>
<ul class="widget-list">
  <li class="category-level-1 category-child category-level-odd"><a href="">产品1000</a></li>
  <li class="category-level-1 category-child category-level-odd"><a href="">产品2000</a></li>
</ul>
</li>
<li class="category-level-0 category-parent">
<a href="">新闻</a>
<ul class="widget-list">
  <li class="category-level-1 category-child category-level-odd"><a href="">新闻1</a></li>
  <li class="category-level-1 category-child category-level-odd"><a href="">新闻2</a></li>
</ul>
</li>
</ul>
</code>

在网上找到一个输出全部为[a href]的方法

<code>    <?php $this->widget('Widget_Metas_Category_List')->to($category); ?>
    <?php while ($category->next()): ?>
    <a href="<?php%20%24category->permalink();%20?>"><?php $category->name(); ?></a>
    <?php endwhile; ?>
</code>

我想输出全部为[a href]添加相应class 应该怎么写呢

<code><a class="category-level-0 category-parent" href="">产品</a>
<a class="category-level-1 category-child category-level-odd" href="">产品1000</a>
<a class="category-level-1 category-child category-level-odd" href="">产品2000</a>
<a class="category-level-0 category-parent" href="">新闻</a>
<a class="category-level-1 category-child category-level-odd" href="">新闻1</a>
<a class="category-level-1 category-child category-level-odd" href="">新闻2</a>
</code>

<code><?php $this->widget('Widget_Metas_Category_List')->to($category); ?>
<?php while ($category->next()): ?>
<a class="category-level-<?php if($category->isParent()): ?>0 category-parent<?php else: ?>1 category-child category-level-odd<?php endif;?>" href="<?php%20%24category->permalink();%20?>"><?php $category->name(); ?></a>
<?php endwhile; ?>
</code>

isParent() 这个方法应该怎么写呢?
输出这样的结构<a class="category-level-0 category-parent" href="">产品</a>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn