当在主循环中的帖子上显示WordPress格式的the_post_thumbnail()图像时,有没有一种方法可以在可用的地方显示图像标题。
谢谢!感谢所有人的帮助。
发布于 2011-06-06 19:32:27
我想通了:
/************************************************************\
* Fetch The Post Thumbnail Caption
\************************************************************/
function the_post_thumbnail_caption() {
  global $post;
  $thumbnail_id    = get_post_thumbnail_id($post->ID);
  $thumbnail_image = get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment'));
  if ($thumbnail_image && isset($thumbnail_image[0])) {
    echo $thumbnail_image[0]->post_excerpt;
  }
}发布于 2011-07-16 00:21:49
下面是一个更简单、更简短的代码:
<?php the_post_thumbnail();
echo get_post(get_post_thumbnail_id())->post_excerpt; ?>发布于 2016-08-19 17:08:03
从Template4.6开始,函数the_post_thumbnail_caption()已经被添加到核心中(/wp-includes/post- WordPress -template.php)。
使用此处发布的代码将导致错误:
Fatal error: Cannot redeclare the_post_thumbnail_caption()https://stackoverflow.com/questions/6248872
复制相似问题