FFan丶Blog / ICMS / / icms7文章内随机图片(利用icms广告系统)

icms7文章内随机图片(利用icms广告系统)

分类:ICMS 发布时间:2025-02-12 15:29:38来源:FFan丶Blog
1.打开文章内广告 后台>系统>应用管理>钩子管理>文章系统方法修改为正文插入广告 2.修改广告系统文件 /app/plugin/plugin_textad.class.php 修改...

1.打开文章内广告

后台>系统>应用管理>钩子管理>文章系统方法修改为正文插入广告

2.修改广告系统文件

/app/plugin/plugin_textad.class.php

修改

$ad = '<script>if(typeof showBodyUI==="function")showBodyUI("body.' . $i . '");</script>';

$dir = 'style/img/'; // 本地图库路径

$files = scandir( $dir );

// 过滤掉 '.' 和 '..',只保留图片文件

$images = array_filter( $files, function ( $file )use( $dir ) {

  // 只保留图片文件类型(jpg, jpeg, png, gif)

  return in_array( pathinfo( $file, PATHINFO_EXTENSION ), [ 'jpg', 'jpeg', 'png', 'gif' ] );

} );

// 获取协议部分(http 或 https)

$protocol = ( !empty( $_SERVER[ 'HTTPS' ] ) && $_SERVER[ 'HTTPS' ] !== 'off' || $_SERVER[ 'SERVER_PORT' ] == 443 ) ? "https://" : "http://";

// 获取主机名部分(www.example.com)

$host = $_SERVER[ 'HTTP_HOST' ];

// 拼接协议和主机名得到基本域名

$baseDomain = $protocol . $host;

// 确保有图片文件

if ( !empty( $images ) ) {

  // 从数组中随机选择一张图片

  $randomImage = $images[ array_rand( $images ) ];

  // 构造新的 HTML 代码,替换为随机图片

  $ad = '<p>' . '<img src="' . $baseDomain . '/' . $dir . $randomImage . '">' . '</p>';

} else {

  // 如果没有图片文件,给出提示

  $ad = '<p>No images.</p>';

}

上一篇:{Hash@ID} 伪静态

下一篇:ICMS8部分标签

猜你喜欢

  • 文章列表 文章标题:<!--{$article_list.title}--> 文章链接:<!--{$article_list.url}--> 图片属性:pic="true" 随机排序:orderby="rand" 行号 (从1开始):<!--{$article_list.rownum}--> 

    ICMS2020-01-15
  • .pagelist a,.pagelist span {border-style: solid;border-width: 1px;border-color: #e91e63;margin: 5px;padding: 4px 10px;} .pagelist span.page_nowindex {background-color: #e91e63;}

    ICMS2020-01-15
  • 获取 10个分类下 每个分类最新的10篇文章<!--{iCMS:category:list loop="true" row="10"}--> <a href="<!--{$category_list.url}-->"><!--{$category_list.title}--></a>  <!--{iCMS:article:list loop="true" row="10" cid="$category_list.cid"}-->    <a href="<!--{$article_list.url}-->&quo

    ICMS2020-01-20
  • 一般的文字截断(适用于内联与块):.text-overflow {     display:block;/*内联对象需加*/     width:31em;/*指定宽度*/     word-break:keep-all;/* 不换行 */

    CSS2020-04-13
  •     <!-- 声明文档使用的字符编码 -->     <meta charset='utf-8'>     <!-- 优先使用 IE 最新版本和 Chrome -->     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>

    html相关标签2020-07-06