若想实现外链特色图像的功能是可以使用插件:Featured Image Via URL,不过奇怪的是WordPress官方据说对它进行封杀,并且实际上只是将外链图片转存到本地服务器上而已。WP酷只能将以前积累的代码拿出来分享给大家,实现效果为:替换原本特色图像功能,设置外链缩略图。
Functions.php:
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; }
调用方式:
<img src="<?php echo mmimg(get_the_ID()); ?>" alt="" />
在问一下 若是没有特色图片以及里面的图片要怎么办 这个能不能解决下!
哦哦 你看我的博客就知道了。。。顺带问一下 网站很丑吗?
好文章,收藏了
好文章谢谢分享
默认图片怎么设置呢
可以用,但是图片好像太大了
自动调取第一张图是实现了,能不能把文章中的外链图片自动剪裁到一个设定值在调用到首页。
这个调用方法能否说明一下?