Get custom size of thumbnails

时间:2015-05-25 作者:Toni Michel Caubet

这是我当前检索幻灯片的方式:

<?php
    $args = array(
        \'ignore_sticky_posts\' => 1,
        \'posts_per_page\' => 20,
        \'post_type\' => \'slide\'
    );
    $slides = new WP_Query( $args );    
    ?>

    <?php if($slides->post_count > 0) :?>
    <div class="slideshow">         
            <ul class="slides">
                <?php $i = 1; while ($slides->have_posts()) : $slides->the_post(); ?>
                <?php
                //Get slide options         
                $slide_background_img = wp_get_attachment_image_src(get_post_meta($post->ID, "_ttrust_slide_background_image", true), \'full\');          
                $slide_background_img = $slide_background_img[0];

                $s_styles = "";
                $s_class = "";
                if($slide_background_img){
                    $s_styles .= "background-image: url(".$slide_background_img.");";                           
                }       
                ?>                  

                <li id="slide<?php echo $i; ?>" <?php post_class($s_class); ?> style="<?php echo $s_styles;?>"> 
和在函数中。php我设置了拇指大小:

add_theme_support(\'post-thumbnails\');  
add_image_size( \'vip-thumb\', 1024, 9999 ); //300 pixels wide (and unlimited height)
如果在早期代码中,我更改:

$slide_background_img = wp_get_attachment_image_src(get_post_meta($post->ID, "_ttrust_slide_background_image", true), \'full\');

$slide_background_img = wp_get_attachment_image_src(get_post_meta($post->ID, "_ttrust_slide_background_image", true), \'vip-thumb\');

$slide_background_img = wp_get_attachment_image_src(get_post_meta($post->ID, "_ttrust_slide_background_image", true), \'vip-thumb\', true);
我没有调整大小的拇指,只有原始图像

知道我做错了什么吗?

1 个回复
最合适的回答,由SO网友:dea 整理而成

也许你需要使用set_post_thumbnail_size(); 缩略图?然后the_post_thumbnail(\'vip-thumb\' );

https://codex.wordpress.org/Function_Reference/set_post_thumbnail_size

结束

相关推荐

定义`GET_POST_QUALUALY_Images`的大小,它们似乎已调整为150x150

我正在使用get_post_gallery_images 它可以输出150x150的图像。它看起来不需要大小参数,所以我假设它只会显示最大的图像,或者最好是我定义的一个大小。150x150太小了,有没有地方可以声明我想要多大尺寸的画廊图片?例如,我正在做:<?php $gallery = get_post_gallery_images( $post ); foreach ($gallery as $img) { ?> <li><img src