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>';
}
如果文章对你有帮助,欢迎点击上方按钮打赏作者
版权声明:若无特殊注明,本文皆为( FFan )原创,转载请保留文章出处。