• I would like to able to list the latest video attachment uploaded to a post, wrapped in an if/else statement so that if no video has been uploaded no link is displayed.

    How would I go about getting a video attachment link from the post I am currently viewing.

    I have done this with images by using the following in functions.php

    <?php
    function postimage($size=medium) {
    	if ( $images = get_children(array(
    		'post_parent' => get_the_ID(),
    		'post_type' => 'attachment',
    		'numberposts' => 1,
    		'post_mime_type' => 'image',)))
    	{
    		foreach( $images as $image ) {
    			$attachmenturl=wp_get_attachment_url($image->ID);
    			$attachmentimage=wp_get_attachment_image( $image->ID, $size );
    
    			echo $attachmentimage;
    		}
    	} else {
    		echo "";
    	}
    }
    ?>

    and then using

    <?php postimage('thumbnail'); ?>

    where i want to show the image. Is there something similar for video attachments or could I modify or add to the above code and if so how.

    Thanks in advance.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘List Video Attachment’ is closed to new replies.