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条)

报告相同问题?

悬赏问题

  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用