当前位置:网站首页>DEDECMS织梦文章内容里图片自动添加a链接点击新窗口打开图片
DEDECMS织梦文章内容里图片自动添加a链接点击新窗口打开图片
2022-07-20 19:40:00 【米米素材网】
织梦文章内容图片没整之前
织梦文章内容图片自动添加a链接点击新窗口打开图片之后
第一种实现方法,jquery
<script type="text/javascript">
$(function() {
$('.show-article img').each(function(i){
if (!this.parentNode.href) {
$(this).wrap("<a href='"+this.src+"' target='_blank'></a>");
}
});
});
</script>
注意:
1、前提是你当前页面有jquery库
2、你的文档内容外围div里的class或者id,改成自己的
第二种实现方法,PHP
1、在 /include/extend.func.php 最下面加入
/**
* 文档内容图片自动添加a链接新窗口打开图片
*
* @access public
* @param string $body 内容
* @return string
*/
function setBodyimg($body)
{
$matches = array();
preg_match_all('/<img[^>]*src\s*=\s*([\'"]?)([^\'">]*)\1(.*?)>/isu', $body, $matches);
$img_array = $matches[0];
$src_array = $matches[2];
foreach ($img_array as $key => $value)
{
$body = str_replace($value, "<a href='{$src_array[$key]}' target='_blank'>".$value."</a>", $body);
}
return $body;
}
2、把内容模板里的调用内容的标签
{dede:field.body/}
改成
{dede:field.body function="setBodyimg(@me)"/}
完成
边栏推荐
猜你喜欢
Map和Set知识点
Simple student management system project: (add, delete, check, change, fuzzy check, paging check, upload, download, video import, current system time) -- "source code attached"
Help enterprises' digital upgrading, and volcano engine releases cloud growth solutions
IIC通信协议
Postman 最被低估的功能,90%的人不知道!
使用nvm安装node成功,安装npm失败(Error while downloading,TLS handshake timeout)
13 个实用的代码片断,建议收藏
大健康产业商业供应链管理系统:采购管理规范化,提高企业采购效益
七大排序知识点
ACL和NAT
随机推荐
SQLite Compare比较表的问题
oh my god
rce(无回显)
ThreadLocal详解
利用ICMP协议反弹shell
BCG localization
STL notes (XII): relevance container - set
For a single document BCG program, why is the title of the toolbar set at the end of cmainframe:: oncreate? Why is it invalid?
MySQL用的一般是什么引擎?
海思AI芯片(Hi35XX): 图像jpg转.bgr升级版
Simple student management system project: (add, delete, check, change, fuzzy check, paging check, upload, download, video import, current system time) -- "source code attached"
Basic understanding of ES6
Commercial supply chain management system of big health industry: standardize procurement management and improve enterprise procurement efficiency
带新人心得
C# 同步 异步 回调 状态机 async await Demo
Don't understand can? One article tells you the CAN protocol!
今天测试告诉我数据同步后,合并数据无效
JVM的前世今生及未来盘点
Win11C盘变红怎么办?Win11C盘变红的清理方法
《MySQL高级篇》四、索引的存储结构