Code function
-
When the homepage header map switch is turned off, the thumb field is the image address, and the article header map can still be displayed -
When the article header switch is turned off, the thumb field is the image address, and the homepage header can still be displayed -
When the header of the first page of the article is closed, the thumb field is the image address, and the header of the first page of the article can be displayed -
When the header switch is turned on, the thumb field is no, and the current article will not display the header -
When the head map switch is turned on, you can press Order of four selections Select display head image
-
When the homepage article header switch is turned off, the thumb field is the image address. You want to display only the header of the current article, or only the homepage header of the current article -
When the homepage header map switch is turned off, the homepage header map will be displayed for the current article.
code analysis
Reference code
public static function whenSwitchHeaderImgSrc($widget){ $options = mget(); $rand = rand(1,$options->RandomPicAmnt); $howToThumb = $options->RandomPicChoice; $random = $widget->widget('Widget_Options')->themeUrl . '/ img/sj/' . $rand . '.jpg'; $pattern = '/\<img.*? src\=\"(.*?)\"[^>]*>/i'; $patternMD = '/\!\ [.*?\]\((http(s)?:\/\/.*? (jpg|png))/i'; $patternMDfoot = '/\[.*?\]:\s*(http(s)?:\/\/.*? (jpg|png))/i'; //Random thumbnail path //Regularly match pictures of/images/sj/under the theme directory (named in numerical order) $attach = $widget->attachments(1)->attachment;// Picture in attachment $thumbField = $widget->fields->thumb; if ($howToThumb == '0'){ return $random; }elseif ($howToThumb == '1' || $howToThumb == '2'){ if (! empty($thumbField)){ return $thumbField; }elseif (isset($attach->isImage) && $attach->isImage == 1){ return $attach->url; }else{ if (preg_match_all($pattern, $widget->content, $thumbUrl)){ $thumb = $thumbUrl[1][0]; }elseif (preg_match_all($patternMD, $widget->content, $thumbUrl)){ $thumb = $thumbUrl[1][0]; }elseif (preg_match_all($patternMDfoot, $widget->content, $thumbUrl)){ $thumb = $thumbUrl[1][0]; }Else {//There are no pictures in the article if ($howToThumb == '1'){ return ''; }else{ return $random; } } return $thumb; } }elseif ($howToThumb == '3'){ if (! empty($thumbField)){ return $thumbField; }else{ return $random; } } } //Output header image address public static function returnHeaderImgSrc($widget,$select){ $options = mget(); $thumbField = $widget->fields->thumb; If (strtoupper ($thumbField)=="NO") {//thumb is no and the header is not displayed directly $imgSrc = ""; }Else {//thumb is not no if (in_array('NoRandomPic-post',$options->indexsetup) && in_array('NoRandomPic-index', $options ->indexsetup) {//Close all if ($thumbField != ""){ $imgSrc = Content::whenSwitchHeaderImgSrc($widget); }else{ $imgSrc = ""; } }else if (!in_array('NoRandomPic-post',$options->indexsetup) && ! in_array('NoRandomPic-index', $options ->indexsetup) {//Enable all $imgSrc = Content::whenSwitchHeaderImgSrc($widget); }Else {//Open and close If (in_array ('NoRandomPic post ', $options ->indexsetup)) if ($select == "post"){ $imgSrc = ""; }else{ $imgSrc = Content::whenSwitchHeaderImgSrc($widget); } }Else {//Do not display the header image of the home page, but display the header image of the article page if ($select == "post"){ $imgSrc = Content::whenSwitchHeaderImgSrc($widget); }else{ $imgSrc = ""; } } } } return $imgSrc; }