2

我想在公司页面上显示博客的内容。然而,我被缩略图卡住了——我已经分配了一个新的图像尺寸(64x48px),我必须得到它的 src。

这是我得到的代码,但它并没有按照我想要的方式工作。

<?php
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
 ?>
<?php
    global $post;
    $args = array('posts_per_page' => 3, 'category' => 632);
    $externalSitePosts = get_posts($args);
    foreach($externalSitePosts as $post) : setup_postdata($post);
?>
<?php
    //This one gets me the src of the original file (full)
    $thumbnail = wp_get_attachment_url(get_post_thumbnail_id($post->ID, 'myResizedThumbnail'));
    echo $thumbnail;

    //This one displays the properly generated thumbanil image with the size as assigned in functions.php (64x48), I need the src though
    $thumbnail1 = the_post_thumbnail('myResizedThumbnail');
    echo $thumbnail1;
?>
<?php endforeach; ?>

谢谢!:)

4

1 回答 1

2

您正在寻找 wp_get_attachment_image_src();

<?php wp_get_attachment_image_src( $attachment_id, $size, $icon ); ?>

它会回来的

[0] => url
[1] => width
[2] => height
[3] => boolean: true if $url is a resized image, false if it is the original.

http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

所以你会这样做:

<?php

$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID), 'myResizedThumbnail' );
echo $thumbnail[0];

?>
于 2013-11-11T13:00:14.833 回答