链接到全尺寸帖子缩略图

时间:2013-02-25 作者:ogni

我正在使用此代码:

<?php
// get portfolio
$args = array( \'post_type\' => \'portfolio\', \'posts_per_page\' => 100, \'orderby\' => \'title\', \'order\' => \'asc\' );
$loop = new WP_Query( $args );    
$port = array();
while ( $loop->have_posts() ) : $loop->the_post();      
        $idx = get_the_ID();
        $year_completed = get_post_meta($idx, \'year_completed\', true);
        $website_addr = get_post_meta($idx, \'website_address\', true);
        $thumb = get_the_post_thumbnail($idx, \'thumbnail\'); //250x200 - featured image
        $title = get_the_title();
        $excerpt = get_the_excerpt();
        $content = get_the_content();

        //get \'Solutions\' terms
        $terms = get_the_terms($idx, \'Solutions\');
        $terms_string = \'\';

        //build up comma delimited string
        foreach($terms as $t){
            $terms_string .= $t->slug . \' \';
        }
        $port[] = array(
            \'id\' => $idx,
            \'year_completed\' => $year_completed,
            \'website\' => $website_addr,
            \'thumb\' => $thumb,
            \'title\' => $title,
            \'content\' => $content,
            \'excerpt\' => $excerpt,
            \'terms\' => $terms,
            \'terms_string\' =>$terms_string, //classifications (comma delimited slugs)
            \'permalink\' => get_permalink(),
        );
endwhile;

$terms = get_terms(\'Solutions\');    

$filters = \'<section id="options" class="clearfix">
            <ul id="filters" class="option-set floated clearfix">
            <li><a href="#filter" data-filter="*" class="selected">show all</a></li>\';                          

            foreach($terms as $t){          
              $filters .= \'<li><a href="#filter" data-filter=".\' . $t->slug . \'">\' . $t->name . \'</a></li>\';// $t->count
            }
            $filters .= \'</ul></section>\';
?>  
以及:

<!-- add this inside entry-content -->
<?php echo $filters; ?>                 
<div id="portfolio">

    <!-- isotope -->
    <ul class="thumbnails isotope">
    <?php foreach($port as $p){ ?>
        <li class="span3 element <?php echo $p[\'terms_string\']; ?>">
            <div class="thumbnail">
                <?php echo $p[\'thumb\']; ?>
                <div class="caption">
                  <h5><a href="<?php echo $p[\'permalink\']; ?>"><?php echo $p[\'title\']; ?></a></h5>
                </div><!-- end caption -->
            </div><!-- end thumbnail -->
        </li>
    <?  } //end foreach ?>
    </ul>

</div><!-- end #portfolio -->
我想将此链接到全尺寸图像
<?php echo $p[\'thumb\']; ?>

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

要获得具有正确大小图像的url,您必须执行一些魔术:

$image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $idx ), "size" );
当然,您应该在末尾输入适当的缩略图大小作为“size”,听起来像是您想要的“full”。

将其作为while变量中的变量,然后在数组中调用如下内容:

\'thumb-link\' => $image_url[0]
(对于子孙后代,相关信息参考Codex:http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src; 此处列出的尺寸:http://codex.wordpress.org/Post_Thumbnails)

结束

相关推荐

Custom Links in Walker Class

我正在创建一个自定义walker类。我需要确定将从添加到菜单的自定义链接Appearace > Menu > Custom Link这样他们就可以使用与页面/帖子链接不同的格式关于如何在walker类中使用if语句实现这一点,有什么想法吗?类似于if (link = custom-link) { // Do something }