get_children() inside custom loop
-
I have a homepage with a list of posts. The post consist of the exerpt, the title, and the first image from the post as thumbnail. The first 2 are no problem, the thumbnail is.
The homepage consist of 3 loops. Two category loops and the standard loop.
I found a function on this forums to get the image when you’re inside the loop.(forgot the link, so sorry for not giving credit)
function display_thumbnail() { $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image'); if($files) : $keys = array_reverse(array_keys($files)); $j=0; $num = $keys[$j]; $image=wp_get_attachment_image($num, 'large', false); $imagepieces = explode('"', $image); $imagepath = $imagepieces[1]; $thumb=wp_get_attachment_thumb_url($num); print "<img src='$thumb' class='thumbnail' />"; endif; }
This is the code for my self-made loops
<?php $my_query = new WP_Query('category_name=sticky_2&showposts=1'); ?> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> // HTML Template code of my post including call to function display_thumbbnail() <?php endwhile ?>
Only the images in de default wordpress loop are working. The functions doesn’t seems to work in my loops.
I found that $files is NULL when the function is called from inside my loop. The function get_post_ID() return the right ID. So I conclude that get_children is not working when called from inside my loop.
Anyone has a clue how to get this working?
thx alot!!
- The topic ‘get_children() inside custom loop’ is closed to new replies.