Typecho 创建独立页面,实现tagcloud
时间:3年前 阅读:8896
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就可以了。
当然,你可以自己修改、添加相应代码
以上代码来自:mrasong
网友评论