Wordpress:print_thumbnail输出错误的URL。文件权限没有区别

时间:2012-06-19 11:46:47

标签: php wordpress permissions thumbnails

我的网站 - http://www.sweetrubycakes.com.au - 最近有缩略图停止工作(他们一直工作到昨天,昨天域名注册商遇到了一些问题,但我所知道的其他任何问题都无法解决)。< / p>

如果您查看来源,则会在网址中看到它们包含太多内容:

<img src="/home2/sweetrub/public_html/wp-content/uploads/et_temp/t-rex-tiny-63339_203x203.jpg" class="item-image" alt="T- Rexcellent">

应该是:

<img src="/wp-content/uploads/et_temp/t-rex-tiny-63339_203x203.jpg" class="item-image" alt="T- Rexcellent">

我认为我没有使用最新版本的主题,但我做了一些调整,不想更新。

输出图像的代码是:

<?php
   $work_count = 0;
   $recent_work_args = apply_filters( 'evolution_recent_work_args', array(
      'showposts' => (int) get_option('evolution_posts_work_num'),
      'category__not_in' => (array) get_option('evolution_exlcats_work')
   ) );
   $recent_work_query = new WP_Query( $recent_work_args );
   while ( $recent_work_query->have_posts() ) : $recent_work_query->the_post();
      ++$work_count;
      $width = apply_filters( 'evolution_home_work_width', 203 );
      $height = apply_filters( 'evolution_home_work_height', 203 );
      $titletext = get_the_title();
      $thumbnail = get_thumbnail($width,$height,'item-image',$titletext,$titletext,true,'Work');
      $thumb = $thumbnail["thumb"];
      $lightbox_title = ( $work_title = get_post_meta($post->ID, 'work_title',true) ) ? $work_title : $titletext;
      $work_description = ( $work_desc = get_post_meta($post->ID, 'work_description',true) ) ? $work_desc : truncate_post( 50, false );
?>
      <div class="r-work<?php if ( 0 == $work_count % 3 ) echo ' last'; ?>">
         <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, 'item-image'); ?>
         <span class="overlay"></span>
         <!--<a href="<?php the_permalink(); ?>" class="more"></a>-->
         <a href="<?php echo esc_url($thumbnail['fullpath']); ?>" class="zoom fancybox" title="<?php echo esc_attr( $lightbox_title ); ?>" rel="work_gallery" style="right: 77px !important;"></a>
         <p><?php echo esc_html( $work_description ); ?></p>
      </div> <!-- end .r-work -->
<?php endwhile; wp_reset_postdata(); ?>

print_thumbnail函数如下所示:

if ( ! function_exists( 'print_thumbnail' ) ){
function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='') {
    global $shortname;
    if ( $post == '' ) global $post;

    $output = '';
    $thumbnail_orig = $thumbnail;

    $thumbnail = et_multisite_thumbnail( $thumbnail );

    $cropPosition = '';

    $allow_new_thumb_method = false;

    $new_method = true;
    $new_method_thumb = '';
    $external_source = false;

    $allow_new_thumb_method = !$external_source && $new_method && $cropPosition == '';

    if ( $allow_new_thumb_method && $thumbnail <> '' ){
        $et_crop = get_post_meta( $post->ID, 'et_nocrop', true ) == '' ? true : false; 
        $new_method_thumb =  et_resize_image( et_path_reltoabs($thumbnail), $width, $height, $et_crop );
        if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
    }

    if ($forstyle === false) {
        $output = '<img src="' . esc_url( $new_method_thumb ) . '"';

        if ($class <> '') $output .= " class='" . esc_attr( $class ) . "' ";

        $output .= " alt='" . esc_attr( strip_tags( $alttext ) ) . "' />";

        if (!$resize) $output = $thumbnail;
    } else {
        $output = $new_method_thumb;
    }

    if ($echoout) echo $output;
    else return $output;
}

}

我看到其他一些帖子表明它是一个文件权限文件夹(wp print_thumbnail function is not working),但这对我来说似乎不起作用。

有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

我认为print_thumbnail是您代码中的问题。而不是print_thumbnail尝试以下选项。

<?php
if ( has_post_thumbnail() ) {
    the_post_thumbnail(); // Outputs <img/> object with src="thumbnail-href"
}
?>

同样,这也有效:

<?php
if ( has_post_thumbnail() ) {
    echo( get_the_post_thumbnail( get_the_ID() ) );
}
?>

Check this stackoverflow answer