Question

I've got this which gets all the posts and shows their title, and excerpt...

<?php 
query_posts( array( 
'post_type' => array(
            'post'
        ),
    'paged' => $paged )
);

if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post();  ?>
<div class="preview">
    <h1><?php the_title();?></h1>
    <div class="excerpt">
        <?php the_excerpt(); ?>
    </div>
</div>
<?php endwhile; ?>
<?php else : ?>
<?php endif; ?>

...but I can't figure out how to list all the associated post attachments as well. So if one of the posts had a couple of PDFs and an image attached to it for example, then the output HTML would be something like:

<div class="preview">
    <h1>Some title</h1>
    <div class="excerpt">
        This is the excerpt...
    </div>
    <ul>
        <li><a href="http://www.domain.com/wp-content/uploads/pdf1.pdf">pdf1</a></li>
        <li><a href="http://www.domain.com/wp-content/uploads/pdf2.pdf">pdf2</a></li>
        <li><a href="http://www.domain.com/wp-content/uploads/image.png">image</a></li>
    </ul>
</div>

Thanks in advance.

Was it helpful?

Solution

You can use get_children(). Set the post_parent param to your current post id.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top