Typecho 创建独立页面,实现tagcloud

时间:2020-08-01   阅读:373

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']."\"&gt;".$tag['name']."</a> ";
        }
    ?>    
<?php  /your code here/  ?>


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

当然,你可以自己修改、添加相应代码

以上代码来自:mrasong


上一篇:Typecho 随机缩略图函数分享

下一篇:Typecho 文章标题字数限制代码

网友评论