Author Topic: How to display media file name?  (Read 1940 times)

awarner20

  • Full Member
  • **
  • Posts: 31
How to display media file name?
« on: April 13, 2010, 11:49:01 am »
Hi all,

I've been looking through the shortcode and advanced tweaks docs as well as searching the forums, but couldn't find the answer. Is it possible to display the media file name? I am using a custom shortcode function to display an archive of posts and somewhere in there I'd like to display the audio file name. The reason is that the people managing the site are having some quality control issues and would like an easy way to determine what media file is being used. All their media files are named by date.

Here's the shortcode function I'm using:

Code: [Select]
function archive_show_post($atts, $content = null) {
      extract(array_merge(array(
              "num" => '10',
              "cat" => ''
      ), $atts));
//        global $post;
      $my_query = new WP_Query('showposts='.$num.'&orderby=post_date&cat='.$cat);
if($my_query->have_posts()) {
  $return='<div id="archive-show-query">';
  while($my_query->have_posts()) {
        $my_query->the_post();
        $return.='<p><a href="'.get_permalink().'">'.get_the_title("","",false).'</a></p>'; 
        $return.='<p>'.get_the_content("","",false).'</p>';
        $return .= '<p>Click Arrow to Play'.powerpress_content('').'</p>';
    }
    $return.='</div> ';
}
return $return;
}
add_shortcode("archive_show", "archive_show_post");

schmoopy

  • Newbie
  • Posts: 2
Re: How to display media file name?
« Reply #1 on: April 15, 2010, 10:29:04 pm »
I would like an answer to this question too - I want to feed the URL to another player via the embed code.  I would also like to display the duration and file size in a different place.

Is there a call for individual elements, something like <?php get_the_powerpress_url(); ?> or similar?  It's pretty much a make or break feature for me.

schmoopy

  • Newbie
  • Posts: 2
Re: How to display media file name?
« Reply #2 on: April 16, 2010, 12:24:45 am »
Seems like there is a part answer in this thread: http://forum.blubrry.com/index.php/topic,1196.0.html

Still no word on the duration/size though!

angelo

  • CIO, RawVoice
  • Administrator
  • Hero Member
  • *****
  • Posts: 4483
Re: How to display media file name?
« Reply #3 on: April 21, 2010, 09:16:25 am »
There are a couple functions you can use when you are in the loop of your WP theme. Please refer to The Loop for more details on that specifically.

The PHP functions in PowerPress powerpress_get_enclosure() and powerpress_get_enclosure_data() are the functions you want to look at. Both functions take 2 parameters, the first parameter is required and should be the post_id. The second parameter is the podcast's WP slug name. The default slug name is 'podcast'. If you have custom Podcast Channels feature enabled, you should know what your other custom podcast slug names are. If you're not using the Custom Podcast Channels feature, you can ignore specifying the second parameter. The powerpress_get_enclosure() returns only the URL and powerpress_get_enclosure_data() returns an associative array of key/value pairs.

To use, simply refer to the post ID when calling the function. e.g.

Code: [Select]
$media_url = powerpress_get_enclosure( get_the_ID() );
echo $media_url;

or
Code: [Select]
$MediaData = powerpress_get_enclosure_data( get_the_ID() );
echo $MediaData['url'];
echo $MediaData['duration'];
echo $MediaData['size'];
echo $MediaData['type'];
if( !empty(echo $MediaData['embed']) )
    echo $MediaData['embed'];

If you enable other podcast entry screen field options, the $MediaData will have additional key/values from those options.

angelo

  • CIO, RawVoice
  • Administrator
  • Hero Member
  • *****
  • Posts: 4483
Re: How to display media file name?
« Reply #4 on: April 21, 2010, 09:24:27 am »
One other tip, if you just want the file name (excluding the URL and path on the server), use the basename() PHP function.

e.g.

Code: [Select]
$filename = basename($url);