我目前正在将我的WP升级到3.2.1到3.5.2,我的帖子中有一部分的特色图片似乎已经消失了。然而,我只是通过phpmyadmin检查了数据库中的wp\\u posts表,并查找了我的一篇有此问题的帖子。我的img
标签是动态生成的,但问题是src
为空。以下是其中一个帖子的示例:
鉴于我的wp\\U posts表中的此记录:
ID post_author post_date post_date_gmt post_content post_title post_excerpt post_status comment_status ping_status post_password post_name to_ping pinged post_modified post_modified_gmt post_content_filtered post_parent guid menu_order post_type post_mime_type comment_count cod_current_ahrf
16169 1 2011-06-17 2011-06-17 Nick-Arias inherit close close Nick-Arias.jpg 0000-00-00 00:00:00 0000-00-00 00:00:00 3728 /images/ahrf/pioneers/legends_face/Nick-Arias.jpg 0 attachment image/jpeg 0
类别图例。php:
if(file_exists($_SERVER{\'DOCUMENT_ROOT\'}.substr($fivesdraft->guid_legend,20)))
{
echo $fivesdraft->ID; // returns 3728
$featured = gangmei_get_the_post_thumbnail_url( $fivesdraft->ID );
echo \'<li class="legends-thumb"><div class="img-wrapper"><a href="/?legends=\'.$fivesdraft->post_name.\'"><img src="\'.$featured.\'" alt="\'.$fivesdraft->name.\'" /></div><p><a href="/?legends=\'.$fivesdraft->post_name.\'">\'.$fivesdraft->name.\'</a></p></li>\';
}
功能。php:
function gangmei_get_the_post_thumbnail_url($post_id = NULL) {
global $id;
$post_id = (NULL === $post_id) ? $id : $post_id;
$edmund = get_post_thumbnail_id($post_id);
echo "post_id = $post_id"; // returns 3728
echo "edmund = $edmund"; // returns 16169
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), \'full\'); //the issue arises here. this returns nothing.
$src = $src[0];
return $src;
}
这就是所产生的:
<img src="" alt="Nick Arias">
. 应该生产的是:
<img alt="Nick Arias" src="/images/ahrf/pioneers/legends_face/Nick-Arias.jpg">
问题是guid
列,您可以看到该记录的该列的值为/images/ahrf/pioneers/legends_face/Nick-Arias.jpg
. 是否可以抓住guid
而不是完成所有这些功能?像这样:
$featured = $fivesdraft->guid;
?
最合适的回答,由SO网友:bigpotato 整理而成
所以我想出来了。我所做的是简化整个过程:
if(file_exists($_SERVER{\'DOCUMENT_ROOT\'}.substr($fivesdraft->guid_legend,20))
{
$thumbnail_id = get_post_thumbnail_id($fivesdraft->ID);
$featured = wp_get_attachment_url( $thumbnail_id );
//$featured = gangmei_get_the_post_thumbnail_url( $fivesdraft->ID );
echo \'<li class="legends-thumb"><div class="img-wrapper"><a href="/?legends=\'.$fivesdraft->post_name.\'"><img src="\'.$featured.\'" alt="\'.$fivesdraft->name.\'" /></div><p><a href="/?legends=\'.$fivesdraft->post_name.\'">\'.$fivesdraft->name.\'</a></p></li>\';
}
但不知道为什么旧版本适用于3.2.1而不是3.5.2。