当前位置:网站首页>pbcms添加循环数字标签
pbcms添加循环数字标签
2022-06-24 20:55:00 【繁华pk落幕】
背景:看到群里有人问想在列表页面分页的时候,新的分页里打开的数字还是从1开始计算.当时想不是很简单吗,直接使用php的循环语句赋值就可以了,后来一想不对劲,模板文件是html后缀的不是.php格式的文件不能直接使用php语句.所以想起之前做的自定义标签.这里就是添加了一个自定义标签.(目的就是把下图从11-20变为1-10)

前端标签
<a href="[list:link]">[list:num][list:title]</a>其中[list:num]是我们新增的标签
修改的后端:
\apps\home\controller\ParserController.php 解析标签的类
修改 public function parserListLabel($content, $cscode = '') 这个方法
找到此方法内的这一句:
foreach ($data as $value) { // 按查询数据条数循环
$one_html = $matches[2][$i];
for ($j = 0; $j < $count2; $j ++) { // 循环替换数据
$params = $this->parserParam($matches2[2][$j]);
$one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
}
$key ++;
$out_html .= $one_html;然后修改以下两句:
foreach ($data as $value) { // 按查询数据条数循环
$one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key);
修改为
foreach ($data as $jb=>$value) { // 按查询数据条数循环
$one_html = $this->parserList($matches2[1][$j], $matches2[0][$j], $one_html, $value, $params, $key,$jb+1);
目的其实就是获取当前循环的角标
然后修改parserList这个方法,新增对list:num的解析
case 'num':
$content = str_replace($search, $num, $content);
break;在结尾default: 之前添加上面的解析.这样就可以正常使用这个[list:num]标签了
边栏推荐
猜你喜欢

Assembly language (3) 16 bit assembly basic framework and addition and subtraction loop

利用 Redis 的 sorted set 做每周热评的功能

天书夜读笔记——深入虚函数virtual

Library management system code source code (php+css+js+mysql) complete code source code

Bi-sql - different join

Bi SQL drop & alter

Bi-sql index
The latest QQ wechat domain name anti red PHP program source code + forced jump to open

Bi SQL constraints

AutoCAD - two extension modes
随机推荐
Audio PCM data calculates sound decibel value to realize simple VAD function
Bi-sql Union
腾讯云WeCity丨产业联合 协同创新 共贺新春!
Default methods for Scala sample classes
4 ans d'expérience de travail, 5 modes de communication Multi - thread ne peuvent pas être décrits, vous osez croire?
Use redis' sorted set to make weekly hot Reviews
Activity lifecycle
ImageView shows network pictures
How about compass stock trading software? Is it safe?
对技术的乐观,正让戴尔取得比想象中更多的成就
新一代可级联的以太网远程I/O数据采集模块
Cloud development technology summit · public welfare programming challenge [hot registration]!
Zuckerberg demonstrated four VR head display prototypes, and meta revealed the "family" of metauniverse
4 years of working experience, and you can't tell the five communication modes between multithreads. Can you believe it?
新手看过来,带你一次性了解“软考”
胰蛋白酶中英文说明书
Novice, let me show you the "soft test" at one time
Convolution and transpose convolution
Transform BeanUtils to achieve list data copy gracefully
activity生命周期