Typecho制作单独Tag标签聚合页面 调用所有标签方式
导读:一般我们在自己制作或者选择的其他人Typecho主题的时候,都会默认单篇文章会有调用单篇文章的标签Tag,且可能在侧栏或者底部会调用部分热门的Tag。不过我们有些朋友希望需要将所有的Tags聚合到一个页面,这里就需要独立制作一个标签模板页面...
一般我们在自己制作或者选择的其他人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的代码,我们可以单独设置到标签页面然后新创建页面作为模板使用。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: Typecho制作单独Tag标签聚合页面 调用所有标签方式
本文地址: https://pptw.com/jishu/666119.html
