typecho创建独立页面,实现tagcloud

首先,在主题文件夹下建立一个新custom 文件,也就是自定义页面文件,命名为:tpl_tags.php

插入以下代码

<?php 
/**
 * _Tag Cloud_
 * 
 * @package custom 
 * 
 */
?>
<?php  /*your code here*/  ?>
    <?php 
        $db = Typecho_Db::get();
        $options = Typecho_Widget::widget('Widget_Options');
        $tags= $db->fetchAll($db->select()->from('table.metas')
                ->where('table.metas.type = ?', 'tag')
                ->order('table.metas.order', Typecho_Db::SORT_DESC));
        foreach($tags AS $tag) {
            $type = $tag['type'];
            $routeExists = (NULL != Typecho_Router::get($type));
            $tag['pathinfo'] = $routeExists ? Typecho_Router::url($type, $tag) : '#';
            $tag['permalink'] = Typecho_Common::url($tag['pathinfo'], $options->index);
            echo "<a href=\"".$tag['permalink']."\">".$tag['name']."</a> ";
        }
    ?>	
<?php  /*your code here*/  ?>

然后在后台添加一个独立页面,展开高级选项->自定义模板->Tag Cloud,缩略名写tags就可以了。

当然,你可以自己修改、添加相应代码,演示 http://mrasong.com/tags/

添加新评论