我正在编辑wordpress主题(colormag)
主题功能不错,但要使它们起作用,必须在帖子中突出显示图像
我的图片全部来自youtube或google图片,因此无法使用这些功能。
我的替代方法是使用catch_image函数,参见代码:
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
$first_img = "/images/default.jpg";
}
return $first_img;
}
当我在索引页上将函数和此代码一起添加时,一切正常
<img src="<?php echo catch_that_image() ?>" >
但是当我尝试使用此主题小部件(图像)
图像与图像不同,它们都很大。
负责widjet的代码是这个
<?php
if ( has_post_thumbnail() ) {
$image = '';
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$image_alt_text = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
$title_attribute = get_the_title( $post->ID );
if ( empty( $image_alt_text ) ) {
$image_alt_text = $title_attribute;
}
$image .= '<figure>';
$image .= '<a href="' . get_permalink() . '" title="' . the_title( '', '', false ) . '">';
$image .= get_the_post_thumbnail( $post->ID, $featured, array(
'title' => esc_attr( $title_attribute ),
'alt' => esc_attr( $image_alt_text ),
) ) . '</a>';
$image .= '</figure>';
echo $image;
}
?>
是否可以更改此代码,使其与catch_that_image函数一起使用?
以便他寻找文章的图像?