帝国CMS按分类输出所有TAG标签
帝国CMS按分类输出所有TAG标签本文关键字词:帝国CMS标签,TAG标签,TAGS
在网站根目录新建一个tag.php文件,加入以下代码即可(样式自行修改)
tag.php Code:<!-- TAG查询代码开始 -->
<?php
require ('./e/class/connect.php'); //引入数据库配置文件和公共函数文件
require ('./e/class/db_sql.php'); //引入数据库操作文件
require ('./e/data/dbcache/class.php'); //引入栏目缓存文件
$link = db_connect(); //连接MYSQL
$empire = new mysqlquery(); //声明数据库操作类
//获得TAG分类
$tagclass_sql = $empire->query("select classid,classname from {$dbtbpre}enewstagsclass where classid!=0 order by classid asc");
while ($tagclass_r = $empire->fetch($tagclass_sql)) {
$tag_all = '';
echo '<div class="tagbqn clearfix"><h3>' . $tagclass_r['classname'] . '</h3>' . PHP_EOL;
/*按分类输出所有已分类TAG*/
$tag_sql = $empire->query("select tagname from {$dbtbpre}enewstags where cid='{$tagclass_r['classid']}' order by tagid desc");
while ($tag_r = $empire->fetch($tag_sql)) {
$tagslink = $public_r['newsurl'] . 'tags-' . urlencode($tag_r['tagname']) . '-0.html'; //TAG标签链接
$tag_all.= '<a href="' . $tagslink . '" title="' . $tag_r['tagname'] . '">' . $tag_r['tagname'] . '</a>';
}
echo $tag_all . PHP_EOL . '</div>' . PHP_EOL;
}
/*其他TAG标签*/
echo '<div class="tagbqn clearfix"><h3>未分类标签</h3>' . PHP_EOL;
/*按分类输出所有TAG*/
$tag_sql = $empire->query("select tagname from {$dbtbpre}enewstags where cid=0 order by tagid desc");
while ($tag_r = $empire->fetch($tag_sql)) {
$tagslink = $public_r['newsurl'] . 'tags-' . urlencode($tag_r['tagname']) . '-0.html'; //TAG标签链接
$tag_other.= '<a href="' . $tagslink . '" title="' . $tag_r['tagname'] . '">' . $tag_r['tagname'] . '</a>';
}
echo $tag_other . PHP_EOL . '</div>' . PHP_EOL;
db_close(); //关闭MYSQL链接
$empire = null; //注消操作类变量
?>
<!-- TAG查询代码结束 -->
以上只是实例代码。更多技巧请自行拓展。
附加例子(ECMS7.5以TAGID伪静态方式):
<!-- TAG查询代码开始 -->
<?php
require ('./e/class/connect.php'); //引入数据库配置文件和公共函数文件
require ('./e/class/db_sql.php'); //引入数据库操作文件
require ('./e/data/dbcache/class.php'); //引入栏目缓存文件
$link = db_connect(); //连接MYSQL
$empire = new mysqlquery(); //声明数据库操作类
//获得TAG分类
$tagclass_sql = $empire->query("select classid,classname from {$dbtbpre}enewstagsclass where classid!=0 order by classid asc");
while ($tagclass_r = $empire->fetch($tagclass_sql)) {
$tag_all = '';
echo '<div class="tagbqn clearfix"><h3>' . $tagclass_r['classname'] . '</h3>' . PHP_EOL;
/*按分类输出所有已分类TAG*/
$tag_sql = $empire->query("select tagid,tagname from {$dbtbpre}enewstags where cid='{$tagclass_r['classid']}' order by tagid desc");
while ($tag_r = $empire->fetch($tag_sql)) {
$tagslink = $public_r['newsurl'] . 'tags-etagid' . $tag_r['tagid'] . '-0.html'; //TAG标签链接
$tag_all.= '<a href="' . $tagslink . '" title="' . $tag_r['tagname'] . '">' . $tag_r['tagname'] . '</a>';
}
echo $tag_all . PHP_EOL . '</div>' . PHP_EOL;
}
/*其他TAG标签*/
echo '<div class="tagbqn clearfix"><h3>未分类标签</h3>' . PHP_EOL;
/*按分类输出所有TAG*/
$tag_sql = $empire->query("select tagid,tagname from {$dbtbpre}enewstags where cid=0 order by tagid desc");
while ($tag_r = $empire->fetch($tag_sql)) {
$tagslink = $public_r['newsurl'] . 'tags-etagid' . $tag_r['tagid'] . '-0.html'; //TAG标签链接
$tag_other.= '<a href="' . $tagslink . '" title="' . $tag_r['tagname'] . '">' . $tag_r['tagname'] . '</a>';
}
echo $tag_other . PHP_EOL . '</div>' . PHP_EOL;
db_close(); //关闭MYSQL链接
$empire = null; //注消操作类变量
?>
<!-- TAG查询代码结束 -->
为什么分类的tag名称会重合
如下图,分类1和飞龙2明明各是各的tag, 但飞龙2包含了分类1的tag
http://bbs.phome.net/ebb_data/tran/2018-07/1532687712.png
jwmm 发表于 2018-7-27 18:32
为什么分类的tag名称会重合
如下图,分类1和飞龙2明明各是各的tag, 但飞龙2包含了分类1的tag
整理失误,已修复! 本帖最后由 jwmm 于 2018-8-1 18:20 编辑
还是老样子。没变化
http://bbs.phome.net/ebb_data/tran/2018-07/1532687712.png jwmm 发表于 2018-8-1 18:19
还是老样子。没变化
已修复,感谢测试和建议
页:
[1]