WordPress:print_thumbnail输出不正确的URL.文件权限没有区别


Wordpress: print_thumbnail outputting incorrect URLs. File permissions not making a difference

我的一个网站 - http://www.sweetrubycakes.com.au - 最近缩略图停止工作(它们直到昨天才工作,昨天域名注册商遇到了一些问题,但我知道的其他任何事情都可能导致它)。

如果您查看源,您会发现它们在 URL 中包含太多内容:

<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功能不起作用),但这似乎对我不起作用。

有人有什么建议吗?

我认为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() ) );
}
?>

检查此堆栈溢出答案