替换原本特色图像功能,设置外链缩略图。
Functions.php:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
add_theme_support( ‘post-thumbnails’ );
function catch_that_image() {
global $post, $posts;
$first_img = ”;
ob_start();
ob_end_clean();
$output = preg_match_all(‘/<img.+src=[\'”]([^\'”]+)[\'”].*>/i’, $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$popimg=get_option( ‘mao10_popimg’);
$first_img = “$popimg”;
}
return $first_img;
}
function mmimg($postID) {
$cti = catch_that_image();
$showimg = $cti;
has_post_thumbnail();
if ( has_post_thumbnail() ) {
$thumbnail_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘thumbnail’);
$shareimg = $thumbnail_image_url[0];
} else {
$shareimg = $showimg;
};
return $shareimg;
}
|
调用方式:
|
1
|
<img src=“<?php echo mmimg(get_the_ID()); ?>“ alt=“” />
|
