displaying an image from a child page custom field on to a parent page (5 posts)

  1. nadine00
    Posted 6 years ago #


    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...

    	$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($count >= 2)
    		$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 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>
    	}	?>

    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.


  2. esmi
    Forum Moderator
    Posted 6 years ago #

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

  3. nadine00
    Posted 6 years ago #

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

  4. abathur
    Posted 6 years ago #

    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.

  5. ahkiam
    Posted 6 years ago #

    +1 for a method to do this.

Topic Closed

This topic has been closed to new replies.

About this Topic