在使用DedeCMS进行网站构建时,有时会遇到需要对采集来的文章内容进行批量修改的情况。如果逐一手动修改每篇文章,将耗费大量时间和精力。因此,DedeCMS提供了一个非常实用的功能——SQL批量替换功能。以下是具体的操作方法和示例:

1. 更改文章中的内容


update dede_addonarticle set body=replace(body,'原来的字符','替换后的字符');
    

例如:将所有文章中的“软件下载”替换为“插件下载”。


update dede_addonarticle set body=replace(body,'软件下载','插件下载');
    

2. 更改缩略图目录


update dede_archives set litpic=replace(litpic,'原来的字符','替换后的字符');
    

例如:将缩略图路径从“uplimg”替换为“tupian”。


update dede_archives set litpic=replace(litpic,'uplimg','tupian');
    

3. 批量替换文章模型中内容部分图片链接路径


update dede_addonarticle set body=replace(body,'src="http://adminbuy.cn/img/','src="http://adminbuy.cn/images/');
    

例如:将图片路径由“http://www.adminbuy.cn/img/”替换为“http://adminbuy.cn/images/”。

4. 批量替换文章模型中内容部分超链接


update dede_addonarticle set body=replace(body,'href="http://www.adminbuy.cn','href="http://adminbuy.cn');
    

例如:将超链接从“http://www.adminbuy.cn”替换为“http://adminbuy.cn”。

5. 批量替换文章模型中内容部分图片锚文本文字


update dede_addonarticle set body=replace(body,'alt="AB模板网','alt="dedecmsCMS模板');
    

例如:将图片的“alt”属性值从“AB模板网”替换为“dedecmsCMS模板”。

6. 批量替换软件模型内容部分超链接


update dede_addonsoft set introduce=replace(introduce,'href="http://www.adminbuy.cn/images/js/test.html','href="http:/adminbuy.cn/index.html');
    

例如:将软件模型中的超链接从“http://www.adminbuy.cn/images/js/test.html”替换为“http:/adminbuy.cn/index.html”。

7. 批量替换文章模型中作者字段


update dede_archives set writer=replace(writer,'http://www.adminbuy.cn','http://adminbuy.cn');
    

例如:将作者信息从“http://www.adminbuy.cn”替换为“http://adminbuy.cn”。

8. 批量替换文章模型中来源字段


update dede_archives set source=replace(source,'AB模板网','dedecmsCMS模板');
    

例如:将来源信息从“AB模板网”替换为“dedecmsCMS模板”。

9. 批量替换文章命名规则


update `dede_arctype` set namerule='{typedir}/{aid}.html';
    

例如:将所有文章的命名规则统一替换为“{typedir}/{aid}.html”。

10. 批量替换软件模型演示地址超链接


update dede_addonsoft set officialUrl=replace(officialUrl,'http:/www.adminbuy.cn','http://adminbuy.cn');
    

例如:将软件模型中的演示地址从“http:/www.adminbuy.cn”替换为“http://adminbuy.cn”。

11. 批量审核文章


update dede_archives set arcrank=0;
    

例如:将所有文章设置为已审核状态(arcrank=0表示仅动态)。

通过以上SQL语句,您可以高效地完成DedeCMS中各种批量替换操作。这些技巧不仅能够节省时间,还能显著提高工作效率。希望这些内容对您有所帮助!