缩略图调用问题:lingyuansitu是我自定义的上传了多张图片的字段,我使用dr_array_rand来随机获取lingyuansitu字段中的一张图为缩略,代码如下:
{module module=lylist catid=1 thumb=1 flag=1 not_flag=$nfnum order=rand num=8 cache=86400}
<?php $t['lingyuansitu'] = dr_array_rand($t['lingyuansitu'], 1);?>
<?php if ($t['lingyuansitu']) { $key=0; foreach ($t['lingyuansitu'] as $c) { ?>
<img src="{dr_thumb($c, 200, 133, 0, 'width')}" class="img-fluid rounded da-ly-listimg" alt="{$t.title}">
<?php $key++;} } ?>
{/module}我的问题是:我希望随机获取一张图片作为缩略图,但是又不希望每次刷新页面图片都在变;想要随机获得的缩略图能保持1天不变,一天后再变。module设置了cache后标题等其他都可以按随机展示1天后更换,就是缩略图每次刷新页面都会变
{module module=lylist catid=1 thumb=1 flag=1 not_flag=$nfnum order=rand num=8 cache=86400} <?php $fkey = md5($t['id'].dr_array2string($t['lingyuansitu'])); $fcache = \Phpcmf\Service::L('cache')->get_auth_data($fkey); if ($fcache) { $t['lingyuansitu']=$fcache; } else { $t['lingyuansitu'] = dr_array_rand($t['lingyuansitu'], 1); \Phpcmf\Service::L('cache')->set_auth_data($fkey, $t['lingyuansitu']); } ?> <?php if ($t['lingyuansitu']) { $key=0; foreach ($t['lingyuansitu'] as $c) { ?> <img src="{dr_thumb($c, 200, 133, 0, 'width')}" class="img-fluid rounded da-ly-listimg" alt="{$t.title}"> <?php $key++;} } ?> {/module}