php - Wordpress - loop image description

794
  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>';
  }
 }

I've seen this code in the net. But it only displays the first image description that has been attached. I'm new in wordpress and still getting problems with coding. How can I put this inside a loop for it to display all the image description that has been attached. Thanks!

143

Answer

Solution:

Try this

<?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>';
         }
        }
      }
?>

People are also looking for solutions to the problem: javascript - How to set cookies for remember me checkbox after login in codeigniter?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.