已解决
公开

考虑到自己的主机空间容量不大,所以想使用微博图床来外链图片。使用微博图床插件后,文章中的图片可以正常显示,但特色图片因为使用了 Timthumb,知言为考虑到安全问题在主题已禁用外链图片。
我按知言的步骤来设置,但还是看不懂。求博主能帮帮忙~~

define ('ALLOW_EXTERNAL', TRUE);
define ('ALLOW_ALL_EXTERNAL_SITES', TRUE);

上面的我已经改过来了。

function post_thumbnail( $width = 100,$height = 80 ){
global $post;
if( has_post_thumbnail() ){ //有缩略图,则显示缩略图
$timthumb_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'full');
$post_timthumb = '<img src="'.get_bloginfo("template_url").'/timthumb.php?src='.$timthumb_src[0].'&h='.$height.'&w='.$width.'&zc=1" alt="'.$post->post_title.'" class="thumb" />';
echo $post_timthumb;
} else{
if ($postid<1)
$postid = get_the_ID();
$image = get_post_meta($postid, "image", TRUE); // 调用自定义域图片
$post_timthumb = '<img src="'.get_bloginfo("template_url").'/timthumb.php?src='.$image.'&h='.$height.'&w='.$width.'&zc=1" alt="'.$post->post_title.'" class="thumb" />';
if ($image != null or $image != '') {
echo $post_timthumb;
} else {
$post_timthumb = '';
ob_start();
ob_end_clean();
$output = preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $index_matches); //获取日志中第一张图片
$first_img_src = $index_matches [1]; //获取该图片 src
if( !empty($first_img_src) ){ //如果日志中有图片
$path_parts = pathinfo($first_img_src); //获取图片 src 信息
$first_img_name = $path_parts["basename"]; //获取图片名
$first_img_pic = get_bloginfo('wpurl'). '/cache/'.$first_img_name; //文件所在地址
$first_img_file = ABSPATH. 'cache/'.$first_img_name; //保存地址
$expired = 604800; //过期时间
if ( !is_file($first_img_file) || (time() - filemtime($first_img_file))> $expired ){
copy($first_img_src, $first_img_file); //远程获取图片保存于本地
$post_timthumb = '<img src="'.$first_img_src.'" alt="'.$post->post_title.'" class="thumb" />'; //保存时用原图显示
}
$post_timthumb = '<img src="'.get_bloginfo("template_url").'/timthumb.php?src='.$first_img_pic.'&h='.$height.'&w='.$width.'&zc=1" alt="'.$post->post_title.'" class="thumb" />';
} else { //如果日志中没有图片,则显示默认
$post_timthumb = '<img src="'.get_bloginfo("template_url").'/images/default.gif" alt="'.$post->post_title.'" class="thumb" />';
}
echo $post_timthumb;
}
}}

上面这一步是不是就是全部复制粘贴上去?

<?php post_thumbnail( 100,100 ) ?>

上面这一步是在哪里调用?
 

2 人关注这个问题
    1. 你用的什么主机,win 还是 Linux?是否用的 tinection 主题? 请填写好资料页中的邮箱以便收取回复邮件~
    2. 你好,我使用 Linux 空间的(虽然 vps 安装成功过,但还是觉得用空间直观点)。并且是用 tinection。我这个小白好想知道如何改上述代码~

    2 答案

    公开
    龙笑天 2016-12-31 19:42 最佳答案

    tinection 开启缩略图(Timthumb.php)支持外链的设置方法如下:
    1.timthumb.php 的参数改一下:

    define ('ALLOW_EXTERNAL', TRUE);
    define ('ALLOW_ALL_EXTERNAL_SITES', TRUE);

    2.在后台-主题设置-阅读 选项卡中,开启这个设置:“Timthumb.php 缩略图裁剪”
    3.注意事项: 
    a.为 Timthumb.php 文件以及同级下 cache 文件夹、cache 下 index.html 文件赋予 755 权限,不可太高,特别是给 Group 组写的权限也将导致安全问题报错,cache 文件夹是图片裁剪缓存目录,index.html 是图片裁剪过程临时输出文件;
    b.Windows 主机用户注意:请直接删除 cache 文件夹,这是 windows 主机程序安全验证与 linux 的不同点。

    把你添加的一些代码删掉,然后按照我这个来操作试试~

    #
    公开
    龙笑天 2016-12-31 19:42 最佳答案

    tinection 开启缩略图(Timthumb.php)支持外链的设置方法如下:
    1.timthumb.php 的参数改一下:

    define ('ALLOW_EXTERNAL', TRUE);
    define ('ALLOW_ALL_EXTERNAL_SITES', TRUE);

    2.在后台-主题设置-阅读 选项卡中,开启这个设置:“Timthumb.php 缩略图裁剪”
    3.注意事项: 
    a.为 Timthumb.php 文件以及同级下 cache 文件夹、cache 下 index.html 文件赋予 755 权限,不可太高,特别是给 Group 组写的权限也将导致安全问题报错,cache 文件夹是图片裁剪缓存目录,index.html 是图片裁剪过程临时输出文件;
    b.Windows 主机用户注意:请直接删除 cache 文件夹,这是 windows 主机程序安全验证与 linux 的不同点。

    把你添加的一些代码删掉,然后按照我这个来操作试试~

    #1
    公开

    问下楼主,微博图床插件你还能用吗,我试了失效了,不能登录。
    有可用的吗,求分享

    #2
    1. 这个不大清楚哎,可以去问问插件作者试试~ 我用的是七牛的云存储,登录七牛,上传图片,然后获取图片链接,复制粘贴链接地址到文章中。微博的话,可以用这个地址(http://photo.weibo.com/photos/upload)上传图片,然后获取图片链接地址吧~

    来提交答案

    扫一扫二维码分享
    ×