DedeCMS sql 调用数字递增标签以及修改方法
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>在<span>{dede:arclist/}</span>这个标签中大家都知道有个<span></span> ,这个变量每生成一行就+1,那很多人希望<span>{dede:sql/}</span>标签也需要加上这个功能,很多朋友提问,肯定会认为官方不会去做,其实不然,官方主要希望大家能够一同分享这种使用、开发的小技巧,小经验,其实这个东西很简单,自己稍微摸索下就可以知道。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
下面我们就开始增加这个小扩展,我们知道在V5.3中织梦的标签已经分离出来,也就是类似于arclist这样的标签可以自己修改或者二次开发,程序这些标签存放的目录在/include/taglib文件夹下面,我们可以看那个文件名,就很容易知道这些标签文件名和标签的对应关系。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
那我们现在需要修改的是<span>{dede:sql/}</span>这个标签,那我们就修改sql.lib.php这个文件。<br>
打开后我们找到第34行,也就是代码</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<span>$ctp->LoadSource($Innertext);</span></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
处,在下面加上以下一段代码:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
<span>$GLOBALS['autoindex'] = 0;</span></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
这段代码就是定义一个全局变量,并赋值为0,接下来我们只需要将下面代码进行下修改:<br>
</p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode2" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
while($row = $dsql->GetArray($thisrs)) <br>
{ <br>
$sqlCt++; <br>
foreach($ctp->CTags as $tagid=>$ctag){ <br>
if(!empty($row[$ctag->GetName()])){ $ctp->Assign($tagid,$row[$ctag->GetName()]); } <br>
} <br>
$GLOBALS['autoindex']++; //每循环一次加上一个1然后解析出来 <br>
$revalue .= $ctp->GetResult(); <br>
} </div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这样一来,这个标签就可以在那个{dede:sql/}中使用了,我们举个例子: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<div class="right">
<span><u>复制代码</u></span>
</div>
<p>
代码如下:</p>
</div>
<div class="msgborder" id="phpcode3" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
{dede:sql sql='select * from dede_archives'} <br>
-</br> <br>
{/dede:sql} </div>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>怎么样?很简单吧,其实这种扩展还有很多很多,自己可以试试哦。</span></p>
頁:
[1]