当前分类的mid

这个相当不好理解
$this->_pageRow['mid']

不同分类不同模板

也是因为这个才找到了上面那个的解决办法

<?php if (in_array($this->_pageRow['mid'],array(1,8,11,15,16,17,21))) : echo 'caonima';endif; ?>

只显示当前分类的子分类

用于大分类内容的子分类显示,这个就更难了
参考:https://xiamp.net/archives/27.html
把下面的listSubCategories函数放到主题的functions.php就可以用了。

/**
 * 列出子分类
 *
 * @param mixed $category
 * @param mixed $categoryOptions
 * @return void
 */
public static function listSubCategories($category = null, $categoryOptions = null)
{
    if ($category === null) {
        return;
    }

    $widget = Typecho_Widget::widget('Widget_Metas_Category_List');
    $categoryOptions = Typecho_Config::factory($categoryOptions);
    $categoryOptions->setDefault(array(
        'wrapTag' => 'ul',
        'wrapClass' => '',
        'itemTag' => 'li',
        'itemClass' => '',
    ));
    $subCategories = $widget->getCategories($widget->getAllChildren($category));
    if (count($subCategories)) {
        echo "<" . $categoryOptions->wrapTag . (!empty($categoryOptions->wrapClass) ? ' class="' . $categoryOptions->wrapClass . '"' : '') . ">";
        foreach ($subCategories as $subCategory) {
            if ($subCategory['parent'] === $category) { // 不继续寻找子子分类
                echo "<" . $categoryOptions->itemTag . (!empty($categoryOptions->itemClass) ? ' class="' . $categoryOptions->itemClass . '"' : '') . '><a href=' . $subCategory['permalink'] . '>' . $subCategory['name'] . '</a></' . $categoryOptions->itemTag . '>';
            }

        }
        echo "</" . $categoryOptions->wrapTag . ">";
    }
}

使用方式很简单,在archive.php需要列出子分类链接的地方加入以下代码

<?php if($this->is('category')) { listSubCategories($this->_pageRow['mid'], 'wrapClass=no-dots'); }?>

而我测试之后呢,只能显示当前分类的子分类,更下级的分类就不显示了。所以还需要改。
所以就改了文件\var\Widget\Metas\Category\list.php 420行往后

    /**
     * 获取多个分类 
     * 
     * @param mixed $mids 
     * @access public
     * @return array
     */
    public function getCategories($mids)
    {
        $result = array();

        if (!empty($mids)) {
            foreach ($mids as $mid) {
                if (!$this->parameter->ignore
                    || ($this->parameter->ignore != $mid
                    && !$this->hasParent($mid, $this->parameter->ignore))) {
                    $result[] = $this->_map[$mid];
                }
            }
        }

        return $result;
    }

修改为:

    /**
     * 获取多个分类
     *
     * @param mixed $mids
     * @access public
     * @return array
     */
    public function getCategories($mids)
    {
        $result = array();
        $this->parameter->setDefault('view=0');
        $view = $this->parameter->view;
        if (!empty($mids)) {
            foreach ($mids as $mid) {
                if($view) {
                    if ($view == $mid || $this->hasParent($mid, $this->parameter->view)) {
                        $result[] = $this->_map[$mid];
                    }
                } else{
                    if (!$this->parameter->ignore
                        || ($this->parameter->ignore != $mid
                        && !$this->hasParent($mid, $this->parameter->ignore))) {
                        $result[] = $this->_map[$mid];
                    }
                }
            }
        }
        return $result;
    }

调用方法

<?php $this->widget('Widget_Metas_Category_List@options','view=1')->listCategories('wrapClass=topnav'); ?>

先记录备份备用,不一定用的上,还是jquery更强大。