pbootcms标签{pboot:list}里添加新的字段(例:副栏目的小图)

1,找到ParserController.php,添加代码

路径:\apps\home\controller\ParserController.php

作用:该文件的作用之一,便是识别标签代码,如:“[list:title]”

修改:大约在3580行,注释为“// 解析列表标签”的方法里,添加新的case。

 原代码:

1
2
3
4
5
6
7
case 'subsortname':
if ($data->subsortname) {
 $content = str_replace($search, $this->adjustLabelData($params, $data->subsortname, $label), $content);
} else {
 $content = str_replace($search, '', $content);
}
break;

 

添加新代码后:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
case 'subsortname':
 if ($data->subsortname) {
 $content = str_replace($search, $this->adjustLabelData($params, $data->subsortname, $label), $content);
} else {
 $content = str_replace($search, '', $content);
}
break;
case 'subsortico':
if ($data->subsortico) {
  $content = str_replace($search, $this->adjustLabelData($params, $data->subsortico, $label), $content);
} else {
  $content = str_replace($search, '', $content);
}
break;

  

对应的标签则是[list:subsortico]。

 

2,找到ParserModel.php,添加代码

路径:\apps\home\model\ParserModel.php

作用:调用数据库,从数据库中取出数据

修改:大约在300和415行,在“$fields = array(”里添加代码:

1
'c.ico as subsortico',//副栏目的小图字段ico,重取新名"subsortico"

  

完整的实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
$fields = array(
                'a.*',
                'b.name as sortname',
                'b.filename as sortfilename',
                'c.name as subsortname',
                'c.filename as subfilename',
                'c.ico as subsortico',
                'd.type',
                'd.name as modelname',
                'd.urlname',
                'e.*',
                'f.gcode'
);

  

3,最后在模板页面里添加自己新定义的标签[list:subsortico]

代码:

1
2
3
4
5
6
7
{pboot:list scode="15" page="0"}
    <li>
        <a href="[list:link]" class="p"><img src="[list:ico]" alt="[list:title]"></a>
        <img src="[list:subsortico]" class="mfg">
        <s>[list:description len='100']...</s>
    </li>
{/pboot:list}

  

posted @   特平庸青年  阅读(888)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示