Typecho制作单独Tag标签聚合页面 调用所有标签方式

一般我们在自己制作或者选择的其他人Typecho主题的时候,都会默认单篇文章会有调用单篇文章的标签Tag,且可能在侧栏或者底部会调用部分热门的Tag。不过我们有些朋友希望需要将所有的Tags聚合到一个页面,这里就需要独立制作一个标签模板页面。

<?php
    /**
    * 全部标签
    *
    * @package custom
    */
//代码
?>
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('component/header.php'); ?>

    <!-- aside -->
    <?php $this->need('component/aside.php'); ?>
    <!-- / aside -->

<header class="bg-light lter wrapper-md">
          <h1 class="m-n font-thin text-black l-h"><?php _me("全部标签") ?></h1>
          <small class="text-muted letterspacing indexWords"><?php $this->options->description() ?></small>
          </header>
<section id="tag_cloud-2" class="widget widget_tag_cloud wrapper-md clear" style="margin-bottom:auto;">
            <h2 id="tag-cloud-title" class="widget-title m-t-none text-md"><?php _me("标签云") ?></h2>
            <?php Typecho_Widget::widget('Widget_Metas_Tag_Cloud','ignoreZeroCount=1&limit=150')->to($tags); ?>
            <?php if($tags->have()): ?>
                <?php while ($tags->next()): ?>
                <span id="tag-clould-color"  style="background-color:rgb(<?php echo(rand(0,255)); ?>,<?php echo(rand(0,255)); ?>,
                    <?php echo(rand(0,255)); ?>)">
                    <a  href="<?php $tags->permalink();?>" target="_blank">
                    <?php $tags->name(); ?></a>
                </span>
               <?php endwhile; ?>
        <div style="margin: 71px;">
        </div>
        <?php endif; ?>
</section>
<style>
#tag-clould-color {
    padding: 5px 10px 5px 10px;
    border-radius: 10px;
    color: #FFFFFF;
    margin: 6px 3px 3px 0;
    display: inline-block;
}
</style>
    <!-- footer -->
    <?php $this->need('component/footer.php'); ?>
      <!-- / footer -->

这里我们直接在模板目录创建一个tags.php模板页面丢进去,然后在后台新建页面,选择 tags.php 作为模板页面就可以。以上是参考:https://www.moewah.com/archives/3397.html 文章中他基于一款主题的,如果我们自己需要需要修改样式。

或者我们可以参考:

<?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> ";
        }
    ?>    

这个是调用所有TAG的代码,我们可以单独设置到标签页面然后新创建页面作为模板使用。

投上你的一票

原创文章,转载请注明出处:https://www.itbulu.com/tp-all-tags.html

上一篇 2020年8月28日 07:39
下一篇 2020年9月3日 09:22

相关推荐

  • 根据Tags标签关键字调用Typecho相关文章

    一般老蒋在做Typecho主题的时候,相关文章的调用我是直接用代码调出的。一般相关文章的调出是可以根据关键字tags、分类相关随机,以及其他的形式。一般我个人比较喜欢使用TAGS标…

    2020年7月20日
  • 如何实现自定义调用Typecho标签的方法

    我们应该知道网站的文章TAGS标签还是很有作用的,甚至有些时候标签的排名比文章都好,所以我们需要在各个页面会调用标签,增加页面的关联。这里我们整理几个常用的Typecho标签调用方…

    2022年1月20日