一、先懂存储分隔规则(核心)
多值字段存储格式:行分隔:|||||| 、列分隔:::::::示例:标题1::::::图片1::::::链接1||||||标题2::::::图片2::::::链接2
||||||:分割每一行数据(多条记录)
:::::::分割单行内的多列字段(每一格内容)
二、内容页调用($navinfor 全局变量)
基础循环(字段名:duozhi,每行 3 列:标题 / 图片 / 链接)
<?php
// 拆分所有行
$rowList = explode('||||||', $navinfor['duozhi']);
$total = count($rowList);
for($i=0; $i<$total; $i++){
// 拆分单行内多列
$col = explode('::::::', $rowList[$i]);
// 跳过空行
if(empty($col[0])) continue;
?>
<li>
标题:<?=$col[0]?>
图片:<img src="<?=$col[1]?>" alt="">
链接:<a href="<?=$col[2]?>">点击</a>
</li>
<?php } ?>只输出第一行、单独取某一列
<?php
$rowList = explode('||||||', $navinfor['duozhi']);
$firstRow = explode('::::::', $rowList[0]);
echo $firstRow[0]; // 第一行第一列
echo $firstRow[1]; // 第一行第二列
?>倒序输出(新增内容放前面)
<?php
$rowList = explode('||||||', $navinfor['duozhi']);
rsort($rowList); // 倒序
$total = count($rowList);
for($i=0; $i<$total; $i++){
$col = explode('::::::', $rowList[$i]);
if(empty($col[0])) continue;
?>
<li><?=$col[0]?></li>
<?php } ?>三、灵动标签 [e:loop] 列表调用($bqr 变量)
列表模板必须勾选:使用程序代码
[e:loop={1,20,0,0}]
<ul>
<?php
$rowList = explode('||||||', $bqr['duozhi']);
$total = count($rowList);
for($i=0; $i<$total; $i++){
$col = explode('::::::', $rowList[$i]);
if(empty($col[0])) continue;
?>
<li>
<span><?=$col[0]?></span>
<img src="<?=$col[1]?>">
</li>
<?php } ?>
</ul>
[/e:loop]四、列表内容模板 list.var 调用
同样勾选「使用程序代码」,变量是 $r
<?php
$rowList = explode('||||||', $r['duozhi']);
$total = count($rowList);
for($i=0; $i<$total; $i++){
$col = explode('::::::', $rowList[$i]);
if(empty($col[0])) continue;
echo '<a href="'.$col[2].'">'.$col[0].'</a>';
}
?>