分类显示问题

模板开发以及发布测试

版主: seita

回复
头像
huangjunjie
帖子: 13
注册时间: 2016年 7月 12日 14:19

分类显示问题

帖子 huangjunjie »

RT,请问如何显示分类名称的分类文章,如下结构:

◆ 分类111
◇ 文章1111
◇ 文章2222
◆ 分类222
◇ 文章3333
◇ 文章4444

代码: 全选

<ul>
   <?php $this->widget('Widget_Metas_Category_List')->to($listCategories); ?>
   <?php while ($listCategories->next()): ?>
   <li><a href="<?php $listCategories->permalink(); ?>"><?php $listCategories->name(); ?></a>
      <ul>
         <?php while($this->next()): ?>
         <li><a itemtype="url" href="<?php $this->permalink() ?>"><?php $this->title() ?></a></li>
         <?php endwhile; ?>
      </ul>
   </li>
   <?php endwhile; ?>
</ul>


这样分类显示了所有文章,怎么才能把文章对应到分类上呀,是不是while下面应该加一个if判断呀,但是判断mid的话它不是动态的目录么,怎么搞的呀。
头像
huangjunjie
帖子: 13
注册时间: 2016年 7月 12日 14:19

Re: 分类显示问题

帖子 huangjunjie »

代码: 全选

<?php while($this->next()): ?>
   [color=#FF0000]<?php if($this->mid()==$listCategories->mid()): ?>[/color]
   <li><a itemtype="url" href="<?php $this->permalink() ?>"><?php $this->title() ?></a></li>
   [color=#FF0000]<?php endif; ?>[/color]
   <?php endwhile; ?>


加了mid只是输出啊,怎么办呀
头像
m4go
帖子: 857
注册时间: 2010年 3月 29日 02:33
来自: https://www.vpshu.com
联系:

Re: 分类显示问题

帖子 m4go »

代码: 全选

<?php $this->widget('Widget_Metas_Category_List')->listCategories('wrapClass=widget-list'); ?>
头像
huangjunjie
帖子: 13
注册时间: 2016年 7月 12日 14:19

Re: 分类显示问题

帖子 huangjunjie »

m4go 写了:

代码: 全选

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


@m4go,这个只是显示默认目录呀,分类的文章名称显示不了,问题我传个图(如下)

图片
头像
m4go
帖子: 857
注册时间: 2010年 3月 29日 02:33
来自: https://www.vpshu.com
联系:

Re: 分类显示问题

帖子 m4go »

试试以下代码,先列出分类,再分类下文章。

代码: 全选

<?php $this->widget('Widget_Metas_Category_List')->to($categories); ?>
<?php while ($categories->next()): ?>


        <div class="col-sm-6">
         <div class="panel panel-block">
          <h2 class="panel-title h3"><a href="<?php $categories->permalink(); ?>"><?php $categories->name(); ?></a></h2>
          <ul class="list-styled list-icon article_list">
           
<?php $this->widget('Widget_Archive@category-' . $categories->mid, 'pageSize=10&type=category', 'mid=' . $categories->mid)->to($posts); ?>

<?php while ($posts->next()): ?>

<li><a target="_blank" href="<?php $posts->permalink(); ?>"><i class="zmdi zmdi-file-text"></i><?php $posts->title(); ?></a></li>


<?php endwhile; ?>

          </ul>
         </div>
        </div>
     
<?php endwhile; ?>
头像
m4go
帖子: 857
注册时间: 2010年 3月 29日 02:33
来自: https://www.vpshu.com
联系:

Re: 分类显示问题

帖子 m4go »

或者,参考:https://app.typecho.me/coder/21.html
头像
huangjunjie
帖子: 13
注册时间: 2016年 7月 12日 14:19

Re: 分类显示问题

帖子 huangjunjie »

m4go 写了:或者,参考:https://app.typecho.me/coder/21.html


@m4go,非常感谢,帮了大忙了! :D
回复