Forums

[resolved] get first attachment from a sub page (4 posts)

  1. downFast
    Member
    Posted 2 years ago #

    hi,
    it is becoming a very frustrating issue as i cannot figure out how and why it is not working. I need to be able to grab the first image from the attachments of my sub pages; have tried everything.

    I need to have it working within this code:

    <ul class="thumb">
    <?php $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID); foreach($pages as $page) { $content = $page->post_content; if(!$content) continue; ?>
    
    <li cass="thumbList" >
    <a href="<?php echo get_page_link($page->ID) ?>" class="clearfix" >
    <h1 class="title"> <?php echo $page->post_title ?></h1>
    	<?php $key_1_value = get_post_meta($page->ID, 'Preview', true);
    	print $key_1_value; ?></a>
    </li>
    <?php } ?>

    help please

  2. downFast
    Member
    Posted 2 years ago #

    any one please?

  3. downFast
    Member
    Posted 2 years ago #

    done..

    <?php
    
    $args = array(
    	'post_type' => 'attachment',
    	'post_parent' => $page->ID,
    	'numberposts' => 1,
    	);
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $attachment) {
    		echo the_attachment_link($attachment->ID, false);
    	}
    }
    
    ?>
  4. gabesands
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.