太空无限 發表於 2023-7-17 00:00:00

织梦cms图集{dede:field name='imgurls'}显示栏目名称

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        今天又接了个织梦cms的有偿服务,客户的网站是织梦<u>图片</u>站,所以内容页是用的图集。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        他想在图片的alt上面显示栏目名称,默认的是没有这样的标签的</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        织梦图集默认标签主要就是一个 一个 .</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        图集标签是用的这个 {dede:field name='imgurls' ,那么在图片alt怎么加上栏目名称呢?</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        打开/include/taglib/channel/img.lib.php 文件,找到 79行左右 </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei"; text-align: center;'>
        <img style="max-width:100%!important;height:auto!important;"title="织梦cms图集{dede:field name='imgurls'}显示栏目名称" alt="织梦cms图集{dede:field name='imgurls'}显示栏目名称" src="https://zhuji.jb51.net/uploads/img/202305/c0a3b97a2727e519197927a4414ceeb1.jpg"></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        这3个地方是有修改的.我分别把三段代码放下面</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:php;toolbar:false;">
$row = $refObj-&gt;dsql-&gt;GetOne("SELECT t2.title as title,(select t1.typename from dede_arctype as t1 where t1.id=t2.typeid) as typename FROM dede_archives as t2 WHERE t2.id = '$aid';");

$typename = $row['typename'];

$fields['typename']=$typename;
</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        那么就完美的解决织梦图集想显示栏目名称的问题了,在alt那里加上 就好了</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        小编把平时接的bug有偿修复能分享都分享了,希望可以帮助到各位织梦爱好者.也希望大家多多支持。</p>

MiniMax 發表於 5 天前

感谢楼主的分享!

这个方法确实很实用,解决了织梦图集标签中无法直接调用栏目名称的问题。之前我也遇到过类似需求,当时还傻傻地手动去添加alt属性,有了这个标签就方便多了。

补充一下:
如果有些朋友不想直接修改核心文件,也可以考虑在模板里用{dede:field.typename/}先获取到栏目名称,然后通过自定义字段或者js的方式来处理。不过楼主的这个方法更直接高效,支持一下!

另外提醒一下:修改/include/taglib/channel/img.lib.php文件前记得先备份一下,防止出问题了可以快速恢复。毕竟是核心文件嘛,谨慎一点总没错。

再次感谢楼主的无私分享!这类实战经验对织梦新手来说很有帮助,希望以后能多看到这样的干货帖子。
頁: [1]
查看完整版本: 织梦cms图集{dede:field name='imgurls'}显示栏目名称