Heim >Backend-Entwicklung >PHP-Tutorial >求助修改typecho分类输出的样式

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

WBOY
WBOYOriginal
2016-06-06 20:42:301067Durchsuche

原本默认分类输出后样式

<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>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn