Support » Fixing WordPress » displaying an image from a child page custom field on to a parent page

  • Hi,

    I’m trying to pull an image from a child page on to a parent page. I am unsure on how to do this. I am using a piece of code I found elsewhere in the forum that displays child pages as posts (it works great for the content), and I’m generating the image using magic fields.

    i’ve used this method previously, but not with a child page set up.

    <?php $postImg = get_post_meta($post->ID, 'book-image', $single = true);?>

    So far, I have this…

    <?php
    	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
    	$count = 0;
    	foreach($pages as $page)
    	{
    		$content = $page->post_excerpt;
    		if(!$content)
    			continue;
    		if($count >= 2)
    			break;
    		$count++;
    		$content = apply_filters('the_content', $content);
    
    	?>
    		<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    		<div class="postImg">
    
    		<?php $postImg = get_post_meta($post->ID, 'book-image', $single = true);?>
    		<img src="<?php echo $postImg;?>" alt="<?php echo the_title();?>" />
    
    		</div>
    
    		<div class="entry"><?php echo $content ?></div>
    		<div class="clear"></div>
    		<div class="orangeLink"><a href="<?php echo get_page_link($page->ID) ?>">Check This Out</a></div>
    
    	<?php
    	}	?>

    I’ve tried working the $postImg bit into the top, but to no avail, and my programming is pretty basic. Any suggestions would be welcomed.

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi

    (@esmi)

    Forum Moderator

    Why are you using get_post_meta? An image is not a post meta field. It’s a post attachment.

    Because I’m using the Magic Fields plugin, and it writes the image location to a custom field.

    I’m curious about this as well, Nadine. We’re publishing reviewed content by external authors and would like to store the names in a variable and then pull them onto the parent page. We’ll try to remember to post if we figure anything out.

    +1 for a method to do this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘displaying an image from a child page custom field on to a parent page’ is closed to new replies.