在织梦的开发中,我们有时候需要对图集中的每张图片单独输出并自定义样式,如果用织梦的dede:productimagelist调用,还是有一定难度的。
下面我们可以对这个类文件进行修改解决这个问题:
方法1:找到:\include\taglib\productimagelist.lib.php 这个文件,在文件中找到如下内容:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">foreach($images as $row)
{
中间省略...
}</span></span>
修改为:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">$GLOBALS['autoindex'] = 1;
foreach($images as $row)
{
$row['autoindex'] = $GLOBALS['autoindex'];
foreach($ctp->CTags as $tagid=>$ctag)
{
if($ctag->GetName()=='array')
{
$ctp->Assign($tagid,$row);
}
else
{
if(isset($row[$ctag->GetName()])){ $ctp->Assign($tagid,$row[$ctag->GetName()]); }
}
}
$revalue .= $ctp->GetResult();
$GLOBALS['autoindex']++;
}</span></span>
内容页图集标签调用方法为:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">{dede:productimagelist}
[field:array runphp=yes]
if(@me['autoindex'] == 1)
{
@me = "<strong>{@me['autoindex']} - <img src='{@me['imgsrc']}'></strong>\n";
}
elseif(@me['autoindex'] == 2)
{
@me = "<p>{@me['autoindex']} - <img src='{@me['imgsrc']}'></p>\n";
}
elseif(@me['autoindex'] == 3)
{
@me = "<span>{@me['autoindex']} - <img src='{@me['imgsrc']}'></span>\n";
}
else
{
@me = "<div>{@me['autoindex']} - <img src='{@me['imgsrc']}'></div>\n";
}
[/field:array]
{/dede:productimagelist}</span></span>
用array runphp的方式,让第一张图片两边加<strong>,第二章加<p>,第三张加<span>,第四张加<div>
方法2:找到:\include\taglib\productimagelist.lib.php 这个文件,在文件中找到如下内容:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">$GLOBALS['autoindex'] = 0;</span></span>
在此代码下边添加如下代码:
找到:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">$revalue .= $ctp->GetResult();</span></span>
在下面加入如下代码:
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">$GLOBALS['autoindex']++;</span></span>
此方法的原理其实和方法1的是一样的。首先让productimagelist.php 这个文件支持autoindex,然后再通过判断autoindex的值分别调用。比如autoindex为0的时候就调用第一张图,依次类推,写法不多说了,有喜欢研究的朋友可以分别验证这两种方法。
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » dedecms织梦图集每张图片单独调用并自定义样式的办法