仅需要修改文件 usr/themes/handsome/libs/Content.php
1.修改函数 whenSwitchHeaderImgSrc
查找函数: 搜索文字 public static function whenSwitchHeaderImgSrc(
.
修改变量 $random
的生成方式,代码片段:
public static function whenSwitchHeaderImgSrc($widget, $index = 0, $howToThumb, $attach, $content, $thumbField)
{
// $randomNum = unserialize(INDEX_IMAGE_ARRAY);
// 随机缩略图路径
// $random = STATIC_PATH . 'img/sj/' . @$randomNum[$index] . '.jpg';//如果有文章置顶,这里可能会导致index not undefined
$num = mt_rand( 1, 23); // 23 为自定义的图片数量
switch( $num )
{
case 1: $image_file = "https://xxx.jpg";break; //自定义的图片地址
case 2: $image_file = "https://yyy.jpg";break;
......
case 23: $image_file = "https://zzz.jpg";break;
};
$random = $image_file;
2.修改函数 echoPostList
首页等位置的图片存在重复的情况,继续修改函数 exportHeaderImg,查找文字 public static function echoPostList(
.
在 while ($obj->next()) {
语句前定义可用图片列表, 可以和 函数 whenSwitchHeaderImgSrc 的图片列表完全不同,代码片段
// 可用头图列表
$imgSrcUnused = array("https://aaaa.jpg",
"bbb",
......
"https://ccc.jpg");
while ($obj->next()) {
替换语句 $parameterArray['imgSrc'] = Content::returnHeaderImgSrc($obj, "index", $index);
, 代码片段:
// $parameterArray['imgSrc'] = Content::returnHeaderImgSrc($obj, "index", $index);
$imgSrcID = array_rand($imgSrcUnused);
$parameterArray['imgSrc'] = $imgSrcUnused[$imgSrcID];
unset($imgSrcUnused[$imgSrcID]);
$parameterArray['linkUrl'] = $obj->permalink;