记录一个dedecms的修改技巧:
采集发布的文章里面图片alt经常是空的,为了方便图片seo,我们一般会alt加上内容。dedecms(5.3)里面,可以通过修改arc.archives.class.php页面达到这个效果。
在arc.archives.class.php页面里搜索下面内容
//设置全局环境变量
$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['aid'],$this->Fields['title'],'archives');
在其后面加上下面代码:
//替换图片Alt为文档标题
$this->Fields['body'] = str_ireplace(array('alt=""','alt=\'\''),'',$this->Fields['body']);
$this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['body']);
$this->Fields['body'] = str_ireplace("<img " ,"<img alt='".$this->Fields['title']."' ",$this->Fields['body']);
模板标签:{dede:field.body/} ,如果是其它字段,可以修改$this->Fields['body'] 为其它的字段名。
效率说明:使用了正则处理,会降低一些生成速度,如果数据量小,则可以忽略。
网站相关
DEDE, 代码, 修改
使用【Sql 标记】调用数据库字段内容,可实现在首页和列表页显示自定义字段内容。
例如我要查询mobile_addoninfos (分类信息)表中 message字段,phone字段
{dede:sql sql="SELECT message,phone FROM mobile_addoninfos LIMIT 0,30"}[field:message/][field:phone/]{/dede:sql}
【注意:Select 字段1 [, 字段N] From 数据表名称】
【注意2:Limit 0 , 30 表示从0记录到30 ,通俗就是返回30条结果,这里可以控制结果条数】
【注意3:SQL语句中查出的所有字段都可以用[field:字段名/]来调用。例如上表查询的message和phone,所以字段调用:[field:你要查询字段名/]】
使用这个功能结合自定义模块可以实现很多不错的DIY效果。
另外使用“在arclist标记中包含附加表指定的字段”的方法只能实现在列表页显示自定义字段,不能实现首页显示。
{dede:arclist}
[field:exhibition_name/]
{/dede:arclist}
网站相关
DEDE, 建站
Mysql替换语句
update ‘表名(比如我案例中的dede_art)’ set 要修改字段名 = replace (要修改字段名,’被替换的特定字符’,'替换成的字符’)
例:
update `dede_art` set title=replace(title,' "IMG border=0 src=Images/hot.gif";','');
MSSQL替换语句:
update 表名 set 字段名=replace(cast(字段名 as varchar(8000)),’abc.com’,’123.com’)
例:
update PE_Article set Content=replace(cast(Content as varchar(8000)),
'http://news.163.com/,'http://www.baizoo.cn/')
其中PE_Article 为表名 Content为字段名 http://news.163.com/为要替换的内容 http://www.baizoo.cn/为替换后的内容。
技术爱好
DEDE
复制字段里的数据命令:
Update table SET 被替换的字段名=被复制的字段名
演示如下
Update dede_archives SET senddate=pubdate
如何手动将同一数据表内不同字段之间的内容批量转换,可以参考下面的命令:
Update table set 字段名=REPLACE(字段名,’原字符串’,'替换的字符串’) where 已知的字段名 LIKE ‘%原字符串%’
应用到本文实例
Update pw_members set yz=REPLACE(yz,’1′,’2′) where yz LIKE ‘%1%’
转载自:http://www.kalvin.cn/?action=show&id=71
技术爱好
DEDE
Recent Comments