Forums

get url of last post image & video attachment (1 post)

  1. adeibiza
    Member
    Posted 7 months ago #

    i mustve tried about 10 different ways of doing this without success

    i have a page using a custom template to show as the "home" page

    grabbing the last post from different categories etc is fine using

    <?php query_posts($query_string . '&cat=10&posts_per_page=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php endwhile; ?>

    etc

    problem has come when ive tried to grab the associated image and video urls so that i can wrap them in a player

    i've found examples of running through an array to output which has worked ok but has displayed every post that has a video attachment eg this within the while loop:

    $docs =& get_children( 'post_parent=the_ID()&post_type=attachment&post_mime_type=video/quicktime' );
    if ( empty($docs) ) {
    	$attachment_url = "#";
    } else {
    	foreach ( (array) $docs as $attachment_id => $attachment ) {
    		$attachment_url =& wp_get_attachment_url( $attachment_id );
    echo $attachment_url;
    	}
    }

    can seem to figure out how to restrict the search on attachments to 1

Reply

You must log in to post.

About this Topic