您现在的位置是:首页 > cms教程 > PbootCMS教程PbootCMS教程

pbootcms自定义标签实现替换标题中的特殊符号

尔珍2024-12-18PbootCMS教程已有人查阅

导读如题:较新在使用pbootcms进行建站,现有的标签不符合自己的一些业务需求,想着自己做个符合自己的业务的标签,于是参考了一下网上的资料以后便开始着手开发了,整个二开还是比较简单,下面放出来需要修改的文件。

如题:较新在使用pbootcms进行建站,现有的标签不符合自己的一些业务需求,想着自己做个符合自己的业务的标签,于是参考了一下网上的资料以后便开始着手开发了,整个二开还是比较简单,下面放出来需要修改的文件。
前端使用标签的地方
我的需求其实是在news.html也就是新闻中文章末尾添加一个自定义图片(根据标题生成一张图片,因为生成图片的方法不能包含特殊符号所以需要把标题中的特殊符号尤其是?去掉)
<!-- 新增图片_dcx-->
<p style="text-align: center;" >
<img style="width:450px;" src=" title='{content:title}'}.png" alt="{pboot:titlereplace title='{content:title}'}" >
</p>
其中{pboot:titlereplace title='{content:title}'}便是我要新增的标签,title这个属性是在下面的parserTitleReplaceLabel方法中进行case判断用的
ParserController.php 解析标签的类
1)在parserAfter方法中新增一行解析入口
$content = $this->parserTitleReplaceLabel($content);
public function parserAfter($content)
{
// 默认页面信息替换
$content = str_replace('{pboot:pagetitle}', $this->config('other_title') ?: '{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
$content = str_replace('{pboot:pagekeywords}', '{pboot:sitekeywords}', $content);
$content = str_replace('{pboot:pagedescription}', '{pboot:sitedescription}', $content);
$content = str_replace('{pboot:keyword}', get('keyword', 'vars'), $content); // 当前搜索的关键字
// 解析个人扩展标签,升级不覆盖
if (file_exists(APP_PATH . '/home/controller/ExtLabelController.php')) {
if (class_exists('app\home\controller\ExtLabelController')) {
$extlabel = new ExtLabelController();
$content = $extlabel->run($content);
}
}
$content = $this->parserSiteLabel($content); // 站点标签
$content = $this->parserCompanyLabel($content); // 公司标签
$content = $this->parserMemberLabel($content); // 会员标签
$content = $this->parserNavLabel($content); // 分类列表
$content = $this->parserSelectAllLabel($content); // CMS筛选全部标签解析
$content = $this->parserSelectLabel($content); // CMS筛选标签解析
$content = $this->parserSpecifySortLabel($content); // 指定分类
$content = $this->parserListLabel($content); // 指定列表
$content = $this->parserSpecifyContentLabel($content); // 指定内容
$content = $this->parserContentPicsLabel($content); // 内容多图
$content = $this->parserContentCheckboxLabel($content); // 内容多选调取
$content = $this->parserContentTagsLabel($content); // 内容tags调取
$content = $this->parserSlideLabel($content); // 幻灯片
$content = $this->parserLinkLabel($content); // 友情链接
$content = $this->parserMessageLabel($content); // 留言板
$content = $this->parserFormLabel($content); // 自定义表单
$content = $this->parserSubmitFormLabel($content); // 自定义表单提交
$content = $this->parserSqlListLabel($content); // 自定义SQL输出
$content = $this->parserQrcodeLabel($content); // 二维码生成
$content = $this->parserPageLabel($content); // CMS分页标签解析(需置后)
$content = $this->parserIfLabel($content); // IF语句(需置之后)
$content = $this->parserLoopLabel($content); // LOOP语句(需置后,不可放到if前面,否则有安全风险)
$content = $this->restorePreLabel($content); // 还原不需要解析的内容
$content = $this->parserReplaceKeyword($content); // 页面关键词替换
$content = $this->parserTitleReplaceLabel($content); // 通用内容替换标签 这里是我新增的
return $content;
}
function.php 替换方法titlereplace()在这里写
function titlereplace($data){
//把? ?都替换为空格
$search = array('?','?',' ','%',',');
return str_replace($search, "_", $data);
}

本文标签:

很赞哦! ()

相关源码

  • (自适应)蓝色自动溶剂萃取仪器设备类网站pbootcms模板下载本模板为溶剂萃取设备、实验室仪器等精密仪器行业设计,采用PbootCMS内核开发,具有高度专业性和行业适配性。模板设计充分考虑了仪器设备行业展示需求,能够呈现各类精密仪器的技术参数、应用场景和解决方案。查看源码
  • (PC+WAP)蓝色弹簧针厂家探针充电连接器设备网站源码下载基于PbootCMS开发的响应式模板,为弹簧针、探针连接器等电子元器件企业设计。模板采用工业蓝主色调,突出产品技术特性,支持多维度展示连接器产品的规格参数与应用场景,帮助制造企业建立专业线上展示平台。查看源码
  • 帝国cms7.5文库范文/付费下载/复制付费/带支付源码免费下载本模板为文库、文档分享、知识付费类平台设计,提供完整的内容变现解决方案。系统支持多种内容展示与付费模式,满足不同场景下的内容价值转化需求,帮助平台实现内容资源的有效管理和商业化运营。查看源码
  • (自适应)代理记账财务会计咨询服务个人公司网站模板该响应式网站模板为代理记账、财政咨询及财务会计类企业设计,基于PbootCMS内核开发。通过自适应手机端的HTML5技术,帮助企业高效构建专业财税服务平台查看源码
  • (自适应响应式)蓝色律师事务所法务团队网站pbootcms模板为律师事务所和法律服务机构打造的专业网站模板,展现法律专业性与权威性,手工编写标准DIV+CSS代码,结构清晰优化,确保高效运行,自动适配电脑、平板和手机等各类设备,提供更好浏览体验查看源码
  • (自适应)英文外贸电子设备网站模板三级子目录基于PbootCMS内核开发的响应式英文网站模板,为外贸企业打造,支持多行业快速适配。通过简洁高效的代码架构,帮助企业低成本构建专业海外形象,实现更好客户触达与订单转化。查看源码
分享笔记 (共有 篇笔记)
验证码: