我为设置了新的尺寸(宽度/高度)Featured Image 并且还设置了使用默认映像(回退映像)的选项
用于Featured Image: 1170/550,默认图像的大小未设置为atm
我的两个问题是:
如何设置用于Featured Image 到我的默认图像是否可以动态调整默认图像的大小,也就是说:
更改Featured Image 默认图像(我的回退img)将自动使用为Featured Image.我现在拥有/使用的代码:
<div class="post-thumbnail">
    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php 
    if ( has_post_thumbnail() ) {
        the_post_thumbnail( \'featured-image\' );
    } else {
        ?>
        <img src="<?php bloginfo(\'template_directory\'); ?>/images/thumb_featured_img.jpg" alt="<?php the_title(); ?>" />
        <?php
    } ?>
</a>
</div>
 用于
Featured Image:
add_image_size( \'featured-image\', 1170, 550, array( \'center\', \'center\' ) );
有没有办法做到这一点,如果有,如何做到?
 
                SO网友:majick
                您可以从全局$_wp_additional_image_sizes 通过图像大小段塞进行阵列,以便:
global $_wp_additional_image_sizes;
$size = \'featured-image\';
$width  = $_wp_additional_image_sizes[$size][\'width\'];
$height = $_wp_additional_image_sizes[$size][\'height\'];
 然后在模板中更改图像属性:
<img src="<?php bloginfo(\'template_directory\'); >/images/thumb_featured_img.jpg" width="<?php echo $width; ?>" height="<?php echo $height; ?>" alt="<?php the_title(); ?>" />