dounangqie4819 2016-01-29 11:19
浏览 68
已采纳

高级自定义字段和缩略图大小(Wordpress)

My client has a website which lists 3 thumbnails, this is great but I need to get a cropped version of the thumbnail rather than the default thumbnail. The thumbnail class is called "type-one".

<?php 
        $i = 0;
        //$query = new WP_Query( array('category_in' => array_merge(array('6'),$subcats)) );
        //$query = new WP_Query( 'post_type=page&post_parent=35&posts_per_page=3' );
        $query = new WP_Query( array(
            'post_type' => 'page',
            'post_parent' => 35,
            'post__not_in' => array( $post->ID ),
            'posts_per_page' => 3
            )
        );
        if ( $query->have_posts() ){
            while ( $query->have_posts() ){
                $query->the_post();
                $fields = get_fields();
                $i++;
    ?>
        <div class="large-4 medium-4 small-6 columns">
        <?php if( $fields['featured_image'] ) { ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php echo $fields['featured_image']['url']; ?>" alt="<?php echo $fields['featured_image']['alt']; ?>" class="margin-bottom" /></a>
        <?php } ?>
            <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
            <?php echo $fields['introduction']; ?>
        </div>

    <?php
    } // while
    } // if have posts
    ?>
  • 写回答

4条回答 默认 最新

  • doutang2382 2016-01-29 14:02
    关注

    Print out the $fields array to see what you're working with. With Advanced Custom fields there is a 'sizes' array on image fields -

    <?php echo $fields['featured_image']['sizes']['thumbnail']; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统