WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. nadine00
    Member
    Posted 4 years ago #

    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

  2. esmi
    Forum Moderator
    Posted 4 years ago #

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

  3. nadine00
    Member
    Posted 4 years ago #

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

  4. abathur
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    +1 for a method to do this.

Topic Closed

This topic has been closed to new replies.

About this Topic