Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * WordPress Function
- * Drop in your functions.php, or create a simple plugin (and drop all your functions there)
- * Parameter $idi : the $post-ID
- * Parameter $type : A full or partial mime-type, e.g. image, video, video/mp4, application/pdf
- * Usage : <a href="<?php echo getAttach($post->ID,'video'); ?>">download video</a>
- */
- function getAttach($idi,$type)
- {
- $empty = "no attach...";
- if ( $files = get_children(array( //do only if there are attachments
- 'post_parent' => $idi,
- 'post_type' => 'attachment',
- 'numberposts' => 1,
- 'post_mime_type' => $type,
- 'order' => 'ASC',
- 'orderby' => 'menu_order'
- ))){
- foreach( $files as $file ){ // only run once, as numberposts = 1
- $file_link = wp_get_attachment_url($file->ID); //get the url for linkage
- }
- return $file_link;
- }
- else
- {
- return $empty;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement