帝国CMS内容页正文插入随机序号的图片

  • 准备命名规则的图片,例如 1a.jpg2a.jpg 等。
  • 使用 PHP 的 rand() 函数随机插入图片。
  • 图片路径固定,名称使用随机数。
  • 示例代码:
<div class="rand">
    <?php
    $string = $navinfor['newstext'];
    $some = "<img ";
    $num = explode($some, $string);
    if (count($num) > 1) {
        echo $navinfor['newstext'];
    } else {
        echo $navinfor['newstext'];
        ?>
        <script>
            document.getElementsByClassName('rand')[0].children[2].innerHTML += 
                '<p><img src="/images/<?=rand(1, 100)?>a.jpg" alt="<?=$bqr['title']?>"></p>';
        </script>
    <?php
    }
    ?>
    <p>[!--page.url--]</p>
</div>

 

posted @ 2024-12-18 10:57  黄文Rex  阅读(59)  评论(0)    收藏  举报