DedeCMS织梦模板为图片自动添加ALT属性为文章标题

  织梦默认的文章图片属性是要自己手动添加的,否则为空,这对网编来说太过于麻烦,而seo又要求图片alt属性一定要全,文章图片的alt属性一般跟标题一样。

  所以余斗就想办法实现了自动添加图片的alt属性,属性内容为文章标题,具体方法为:

  修改文件:Include/ arc.archives.class.php

  模板标签:

  {dede:field.body/}

  如果是其它字段,可以修改

  $this->Fields[‘body’]

  效率说明:使用了正则处理,会降低一些生成速度,如果数据量小,则可以忽略。

  修改方法:

  首先查找打开include/ 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,}[sS]{0,}[“‘s] @isU”,” “,$this->Fields[‘body’]);

  $this->Fields[‘body’] = str_ireplace(“".$this->Fields[‘title’].”‘ “,$this->Fields[‘body’]);</p>
<p>  保存,然后重新生成文章,即可实现文章中图片ALT属性自动以文章标题添加的功能。</p>
</div>
<div id="pay-single-box"></div>
<div class="entry-tags">
<a href="https://www.dhtlly.com/tag/dedecms" rel="tag">
dedecms      </a>
<a href="https://www.dhtlly.com/tag/dede%e6%a8%a1%e6%9d%bf" rel="tag">
dede模板      </a>
<a href="https://www.dhtlly.com/tag/%e7%bb%87%e6%a2%a6%e6%a8%a1%e6%9d%bf" rel="tag">
织梦模板      </a>
</div>
<div class="article-copyright"><span style="color:#ff0000">☉免责声明:本站所有模板均来自用户分享和网络收集,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=1131734965&site=qq&menu=yes">网站客服</a>,我们核实后会立即删除。</span>
<br/>
☉本站提供的源码、模板、软件工具等其他资源,都不包含技术服务,请大家谅解!<br/><a href="https://www.dhtlly.com">pbootcms模板网</a> » <a href="https://www.dhtlly.com/1083.html">DedeCMS织梦模板为图片自动添加ALT属性为文章标题</a></div>
<div class="article-footer">
<div class="xshare">
<span class="xshare-title">分享到:</span>
<a href="javascript:;" title="收藏文章" etap="star" data-postid="1083" class="ripro-star"><i class="fa fa-star-o"></i></a>
<a href="" etap="share" data-share="qq" class="share-qq"><i class="fa fa-qq"></i></a>
<a href="" etap="share" data-share="weibo" class="share-weibo"><i class="fa fa-weibo"></i></a>
</div>
<!--百度收录情况显示-->
百度已收录</div>    </div>
</div>
</article>
<div class="entry-navigation">
<nav class="article-nav">
<span class="article-nav-prev">上一篇<br><a href="https://www.dhtlly.com/1081.html" rel="prev">[精]织梦自定义表单中手机号码和邮箱的验证规则及必填项设置</a></span>
<span class="article-nav-next">下一篇<br><a href="https://www.dhtlly.com/1085.html" rel="next">DEDE织梦文章和列表页均使用拼音,使之更适合于SEO的解决方案</a></span>
</nav>
</div>
<!-- # 标准网格模式... -->
<div class="related-posts-grid">
<h4 class="u-border-title">相关推荐</h4>
<div class="row">
<div class="col-6 col-sm-3 col-md-3 mt-10 mb-10">
<article class="post">
<div class="entry-media">
<div class="placeholder" style="padding-bottom: 66.666666666667%;">
<a  href="https://www.dhtlly.com/1195.html">
<img class="lazyload" data-src="https://www.dhtlly.com/wp-content/themes/ripro/timthumb.php?src=https://www.dhtlly.com/wp-content/themes/ripro/assets/images/thumb/9.jpg&h=200&w=300&zc=1&a=c&q=100&s=1" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="DedeCms会员审核后积分/金币才增加的方法">  
</a>
</div>
<div class="entry-star"><a href="javascript:;" title="收藏文章" etap="star" data-postid="1195" class="ripro-star"><i class="fa fa-star-o"></i></a></div>  </div>
<div class="entry-wrapper">
<header class="entry-header">    
<h4 class="entry-title"><a href="https://www.dhtlly.com/1195.html" title="DedeCms会员审核后积分/金币才增加的方法" rel="bookmark">DedeCms会员审核后积分/金币才增加的方法</a></h4>  </header>                </div>
</article>
</div>
<div class="col-6 col-sm-3 col-md-3 mt-10 mb-10">
<article class="post">
<div class="entry-media">
<div class="placeholder" style="padding-bottom: 66.666666666667%;">
<a  href="https://www.dhtlly.com/1635.html">
<img class="lazyload" data-src="https://www.dhtlly.com/wp-content/themes/ripro/timthumb.php?src=https://www.dhtlly.com/wp-content/themes/ripro/assets/images/thumb/13.jpg&h=200&w=300&zc=1&a=c&q=100&s=1" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="织梦title字数限制的两种方法">  
</a>
</div>
<div class="entry-star"><a href="javascript:;" title="收藏文章" etap="star" data-postid="1635" class="ripro-star"><i class="fa fa-star-o"></i></a></div>  </div>
<div class="entry-wrapper">
<header class="entry-header">    
<h4 class="entry-title"><a href="https://www.dhtlly.com/1635.html" title="织梦title字数限制的两种方法" rel="bookmark">织梦title字数限制的两种方法</a></h4>  </header>                </div>
</article>
</div>
<div class="col-6 col-sm-3 col-md-3 mt-10 mb-10">
<article class="post">
<div class="entry-media">
<div class="placeholder" style="padding-bottom: 66.666666666667%;">
<a  href="https://www.dhtlly.com/2219.html">
<img class="lazyload" data-src="https://www.dhtlly.com/wp-content/themes/ripro/timthumb.php?src=http://***.com&h=200&w=300&zc=1&a=c&q=100&s=1" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="配合dedecms内容模型实现后台输入栏目id前端输出文章列表">  
</a>
</div>
<div class="entry-star"><a href="javascript:;" title="收藏文章" etap="star" data-postid="2219" class="ripro-star"><i class="fa fa-star-o"></i></a></div>  </div>
<div class="entry-wrapper">
<header class="entry-header">    
<h4 class="entry-title"><a href="https://www.dhtlly.com/2219.html" title="配合dedecms内容模型实现后台输入栏目id前端输出文章列表" rel="bookmark">配合dedecms内容模型实现后台输入栏目id前端输出文章列表</a></h4>  </header>                </div>
</article>
</div>
<div class="col-6 col-sm-3 col-md-3 mt-10 mb-10">
<article class="post">
<div class="entry-media">
<div class="placeholder" style="padding-bottom: 66.666666666667%;">
<a  href="https://www.dhtlly.com/875.html">
<img class="lazyload" data-src="https://www.dhtlly.com/wp-content/themes/ripro/timthumb.php?src=https://www.dhtlly.com/wp-content/themes/ripro/assets/images/thumb/10.jpg&h=200&w=300&zc=1&a=c&q=100&s=1" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="dedecms教程:简略标题调用及字数的修改方法">  
</a>
</div>
<div class="entry-star"><a href="javascript:;" title="收藏文章" etap="star" data-postid="875" class="ripro-star"><i class="fa fa-star-o"></i></a></div>  </div>
<div class="entry-wrapper">
<header class="entry-header">    
<h4 class="entry-title"><a href="https://www.dhtlly.com/875.html" title="dedecms教程:简略标题调用及字数的修改方法" rel="bookmark">dedecms教程:简略标题调用及字数的修改方法</a></h4>  </header>                </div>
</article>
</div>
</div>
</div>
</main>
</div>
</div>
<div class="sidebar-column col-lg-3">
<aside class="widget-area">
<div id="search-2" class="widget widget_search"><form method="get" class="search-form inline" action="https://www.dhtlly.com/">
<input type="search" class="search-field inline-field" placeholder="输入关键词,回车..." autocomplete="off" value="" name="s" required="required">
<button type="submit" class="search-submit"><i class="mdi mdi-magnify"></i></button>
</form></div>
<div id="recent-posts-4" class="widget widget_recent_entries">
<h5 class="widget-title">近期文章</h5>
<ul>
<li>
<a href="https://www.dhtlly.com/6002.html">pbcms043(自适应)响应式互联网产品通用网站pbootcms模板 html5蓝色IT设计网络公司网站源码</a>
</li>
<li>
<a href="https://www.dhtlly.com/5996.html">pbcms042蓝色大气互联网工业品牌联盟官网站pbootcms模板整站源码</a>
</li>
<li>
<a href="https://www.dhtlly.com/5989.html">pbcms041(自适应手机版)响应式矿山机械设备类网站pbootcms模板 红色机械配件设计网站源码</a>
</li>
<li>
<a href="https://www.dhtlly.com/5984.html">pbcms040(自适应手机版)响应式物料自动化机械加工类网站pbootcms模板 html5蓝色营销型机械设备网站源码</a>
</li>
<li>
<a href="https://www.dhtlly.com/5979.html">pbcms039(电脑手机同版)机械设备制造类公司网站pbootcms模板 制药机器生产商厂家网站源码</a>
</li>
</ul>
</div><div id="cao_widget_comments-3" class="widget widget-comments"><ul></ul></div><div id="categories-2" class="widget widget_categories"><h5 class="widget-title">分类</h5><form action="https://www.dhtlly.com" method="get"><label class="screen-reader-text" for="cat">分类</label><select  name=

文章归档

Pbootcms模板网 提供优质的模板集合

立即查看 了解详情
Copyright © 2024 Pbootcms模板网 All rights reserved. 陕ICP备19008415号-9 SITEMAP