Hi, I have the below piece of code that i use in my sidebar throughout the site without problem. I am trying to figure out why it does not work with i include it in a non-wordpress file.
I have a web forum integrated with wordpress and i have the required call to wp-blog-header.php and all the other wordpress functions seem to work just fine except for get_children is giving me troubles.
<?php query_posts("cat=3&showposts=5"); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
$files = get_children(
array(
'post_parent' => $post->ID,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order'
)
);
if($files) {
$keys = array_keys($files);
$num = $keys[0];
$firstImageSrc = wp_get_attachment_image_src($num, "medium", $icon);
if ($firstImageSrc <> null) {
echo "<img src=\"{$firstImageSrc[0]}\" width=\"120\" alt=\"$title\" />"; }
<?php endwhile; ?>
<?php else : ?>
<h2>Not Found</h2>
<?php endif; ?>
The code is supposed to return the first image from each post and does so fine throughout the site, but when i use it in the forum it instead returns the first image from the first post i ever made (like 9 years ago).
Does anybody have any idea why it is not referencing the correct post ID?
Thanks!