- A+
修改functions-theme.php中的函数:_get_post_thumbnail
-
function _get_post_thumbnail($size = 'thumbnail', $class = 'thumb') {
-
global $post;
-
$html = '';
-
if (has_post_thumbnail()) {
-
/*$domsxe = simplexml_load_string(get_the_post_thumbnail());
-
$src = $domsxe->attributes()->src;
-
$src_array = wp_get_attachment_image_src(_get_attachment_id_from_src($src), $size);
-
$html = sprintf('<img data-src="%s" class="%s"/>', $src_array[0], $class);*/
-
$domsxe = get_the_post_thumbnail();
-
// print_r($domsxe);
-
preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $domsxe, $strResult, PREG_PATTERN_ORDER);
-
$images = $strResult[1];
-
foreach($images as $src){
-
$html = sprintf('<img data-src="%s" class="thumb">', $src);
-
break;
-
}
-
}else {
-
$post_thumbnail_src = '';
-
ob_start();
-
ob_end_clean();
-
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
-
$post_thumbnail_src = $matches [1] [0]; //获取该图片 src
-
if(empty($post_thumbnail_src)){
-
$random = mt_rand(1, 10);
-
$post_thumbnail_src = get_bloginfo('template_url').'/img/pic/'.$random.'.jpg';
-
}
-
$html = sprintf('<img data-src="%s" class="thumb">', $post_thumbnail_src);
-
}
-
return $html;
-
}
参考:https://www.duoluodeyu.com/1893.html
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫