我想在公司页面上显示博客内容。我被缩略图所困扰 - 我已经分配了一个新的图像尺寸(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; ?>
谢谢! :)
答案 0 :(得分: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];
?>