/**Output article thumbnail laozuo.org*/ function showThumbnail($widget) { //Default thumbnail when the article has no picture $rand = rand(1,5); // Random 1-5 thumbnails $random = $widget->widget('Widget_Options')->themeUrl . '/img/sj/' . $rand . '.jpg'; // Random thumbnail path // $random = $widget->widget('Widget_Options')->themeUrl . '/img/laozuo.jpg'; // If you want only one default thumbnail, please delete the "//" at the beginning of the line $attach = $widget->attachments(1)->attachment; $pattern = '/\<img.*? src\=\"(.*?)\"[^>]*>/i'; if (preg_match_all($pattern, $widget->content, $thumbUrl)) { echo $thumbUrl[1][0]; } else if ($attach->isImage) { echo $attach->url; } else { echo $random; } }
<?php%20showThumbnail($this);% 20?>