Wordpress - 循环图像描述

时间:2013-02-16 18:48:30

标签: php wordpress

  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 '<p>'.$thumbnail_image[0]->post_content.'</p>';
  }
 }

我在网上看到过这段代码。但它只显示已附加的第一个图像描述。我是wordpress的新手,但仍然遇到编码问题。如何将其放入循环中以显示已附加的所有图像描述。谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个

<?php 
     function the_post_thumbnail_caption() {
        global $post;
        $childs = get_children(array('post_parent' => $post->ID));
        if($childs) {
         foreach($childs as $child) {
         echo '<p>'.$child->post_content.'</p>';
         }
        }
      }
?>