Maison >développement back-end >tutoriel php >求助修改typecho分类输出的样式

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

WBOY
WBOYoriginal
2016-06-06 20:42:301067parcourir

原本默认分类输出后样式

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn