我正在尝试从 WordPress 中的 mp3 文件获取一些元数据。特别是长度变量。这是我的一些代码。这里没有显示,但我已经包含了 wp-admin/includes/media.php 文件。当我查看我的页面时http://beta.openskyministry.org/podcasts/ http://beta.openskyministry.org/podcasts/我只看到空标签<itunes:length></itunes:length>
如果您需要其他任何信息来帮助回答我的问题,请告诉我。
$aud_meta = wp_read_audio_metadata($aud_url); ?>
<item>
<title><?php the_title(); ?></title>
<itunes:author><?php echo htmlspecialchars((get_bloginfo('name'))); ?></itunes:author>
<itunes:summary><?php echo htmlspecialchars(strip_tags(get_the_excerpt())); ?></itunes:summary>
<itunes:length><?php echo $aud_meta['length_formatted']; ?></itunes:length>
WordPress 已经存储了媒体元数据,因此无需对其进行检查。解决方案很简单:
add_action( 'wp_head', function(){
global $post;
if ( is_single($post) ) {
$args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'post_parent' => $post->ID,
'post_mime_type' => 'audio'
);
$attachments = get_posts( $args );
if($attachments){
$meta = wp_get_attachment_metadata( $attachments[0]->ID );
echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";
}
}
});
根据记录,wp_read_audio_metadata()
需要文件路径,而不是 URL。如果需要的话,应该是:
$path = get_attached_file( $attachment->ID );
$meta = wp_read_audio_metadata($path);
echo "<itunes:length>{$meta['length_formatted']}</itunes:length>";
Related: Save camera info as metadata on image upload? https://wordpress.stackexchange.com/a/91186/12615
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)