打开内容页模板,找到:[!--newstext--]
改为:

<div id="picture_if">  <div id="random_fallback_img" style="display:none;margin-top:15px;text-align:center;"></div>  [!--newstext--]</div><script>document.addEventListener("DOMContentLoaded", function () {  const content = document.getElementById("picture_if").innerHTML;  if (!/<img/s/i.test(content)) {    // 无图片,则请求随机图    fetch('[!--news.url--]/e/public/randompic.php')      .then(res => res.text())      .then(html => {        document.getElementById("random_fallback_img").innerHTML = html;        document.getElementById("random_fallback_img").style.display = "block";      });  }});</script>


建一个PHP文件,目录及名称为:./e/public/randompic.php

文件内容为:

<?phprequire('../../e/class/connect.php');require('../../e/class/db_sql.php');$link = db_connect();$empire = new mysqlquery();$sql = $empire->query("SELECT titlepic, titleurl, title FROM {$dbtbpre}ecms_news WHERE titlepic<>'' ORDER BY rand() LIMIT 1");if ($r = $empire->fetch($sql)) {    if (!empty($r['titlepic'])) {        echo '<a href="' . $r['titleurl'] . '" target="_blank">';        echo '<img src="' . $r['titlepic'] . '" alt="' . htmlspecialchars($r['title']) . '" style="max-width:100%;border-radius:5px;">';        echo '</a>';    }}db_close();$empire = null;?>