若想实现外链特色图像的功能是可以使用插件: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="" />
我做的比较另类 用字段自动存储调用图片
@air 谁让你那么牛逼呢~打PP。
@air [差得远呢] 不错的网站,很喜欢
@air [差得远呢] 不错的网站,很喜欢
请问需要timthumb支持吗,我试了不显示图像。。
@... 不需要timthumb的,本站正在使用
请问调用方式 是如何操作的?
请问调用方式用在哪里?
调用方式放在哪?
调用 是放在那个文件
问一下 这个能不能如有自己选择特色就显示特色 若是没有就提取文章的第一张的显示 若还是没有就自动添加特色图片 这个博主能不能弄下代码 我php不会 ! 自己写了个简单的主题。。。
亲 怎么设置默认尺寸大小呢? 后台媒体选项设置吗?还是在functions.php 你编写的函数里加呢?请调教!
亲, 我自己添加了一个默认 图片可惜不会PHP 慢慢折腾 应该能折腾出 限制尺寸函数等问题
赞