Focus on cloud service provider activities
Notes on website operation and maintenance

The first image of Typecho calling content is used as thumbnail

If there are images in our Typecho content, we can use the first image as a thumbnail by default. How to set it?

 //The first image as a thumbnail by laozuo.org function showThumbnail($widget) { $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; } }

Call code:

 <img src="<?php%20showThumbnail($this);%20?>">

 

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » The first image of Typecho calling content is used as thumbnail