### [织梦生成tags.php排版错乱怎么办](https://www.prosaas.cn/article/295) **Published:** 2023-03-31T01:08:11 **Author:** 5201314 **Excerpt:** 最近有不少网站管理员反映,使用织梦系统生成 tags.php 文件后,发现页面排版错乱,标签之间间隔不一致,甚… 最近有不少网站管理员反映,使用织梦系统生成 tags.php 文件后,发现页面排版错乱,标签之间间隔不一致,甚至会导致变形。这个问题其实与织梦系统自带的 tags.php 代码有关,而我们则需要对其进行优化。 第一步:修改样式表 在织梦系统自带的 tags.php 文件中,样式表的布局方式是采用表格的形式,这种布局方式容易导致标签之间的间隔错乱,造成页面排版不美观,甚至会出现内容重叠的问题。我们可以采用 DIV+CSS 的布局方式,将样式表的代码修改如下: .tagcloud { margin: 0; padding: 0; font-size: 14px; line-height: 24px; text-align: justify; } .tagcloud a { display: inline-block; margin: 0 5px 5px 0; padding: 4px 10px; background-color: #f2f2f2; border-radius: 3px; color: #666; text-decoration: none; -webkit-transition: color .2s linear, background-color .2s linear; transition: color .2s linear, background-color .2s linear; } .tagcloud a:hover { background-color: #3498db; color: #fff; } 第二步:修改 PHP 代码 在 tags.php 文件中,用于显示标签的代码如下: $tagsql = "SELECT tag,counts FROM \`#@\_\_tagindex\` WHERE tag!='' ORDER BY counts DESC"; $dsql->SetQuery($tagsql); $dsql->Execute(); 这段代码其实是从织梦系统的数据库中读取标签信息,然后按照标签的使用频率进行排序,以便显示。但是这段代码中没有对标签之间的间距做出处理,导致页面排版出现了问题。我们可以在代码中加入一个变量 $i,用于记录循环的次数,然后根据 $i 的值来调整标签之间的间距,代码如下: $tagsql = "SELECT tag,counts FROM \`#@\_\_tagindex\` WHERE tag!='' ORDER BY counts DESC"; $dsql->SetQuery($tagsql); $dsql->Execute(); $i = 1; while($row = $dsql->GetArray()) { $tagname = $row\['tag'\]; $counts = $row\['counts'\]; if($i == 1) { echo "