1

我的一个网站 - 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 函数不起作用),但这似乎对我不起作用。

有没有人有什么建议?

4

1 回答 1

0

I think print_thumbnail is the problem in your code. Instead of print_thumbnail try below options.

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

Similarly, this would also work:

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

Check this stackoverflow answer

于 2012-06-19T12:58:23.423 回答