我有一个博客,我有时用它来做音频剪辑。我想在我博客的首页上放一个音频播放器。
我怎样才能把玩家放在标题后面,或者使其代码成为文章摘录的一部分?
我有一个博客,我有时用它来做音频剪辑。我想在我博客的首页上放一个音频播放器。
我怎样才能把玩家放在标题后面,或者使其代码成为文章摘录的一部分?
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<?php print_audio_attachments_as_html5( $post->ID ); ?>
<div class="entry-content">
<?php the_content(); ?>
请注意,函数位于The Loop, 所以$post->ID
可用。Put the following function at the end of your theme functions file/wp-content/themes/your-theme/functions.php
function print_audio_attachments_as_html5( $post_id )
{
// Parameters for our search
$args_mp3 = array(
\'post_parent\' => $post_id,
\'post_type\' => \'attachment\',
\'numberposts\' => 1, // only one file
\'post_mime_type\' => \'audio/mpeg\', // Mp3 audio mime type
);
$args_ogg = array(
\'post_parent\' => $post_id,
\'post_type\' => \'attachment\',
\'numberposts\' => 1,
\'post_mime_type\' => \'audio/ogg\', // Firefox does not supports Mp3
);
// Get audio files
$mp3 = get_children( $args_mp3 );
$ogg = get_children( $args_ogg );
// If there\'s any result in one of the get_children, execute code
if( $mp3 || $ogg )
{
// Start Audio tag
echo \'<audio loop="loop" autoplay="autoplay" controls="controls">\';
// Mp3 source
if( $mp3 ) {
$id = array_pop( array_keys( $mp3 ) );
$mp3_url = wp_get_attachment_url( $id );
echo \'<source src="\' . $mp3_url . \'" />\';
}
// Ogg source
if( $ogg ) {
$id = array_pop( array_keys( $ogg ) );
$ogg_url = wp_get_attachment_url( $id );
echo \'<source src="\' . $ogg_url . \'" />\';
}
// Close Audio tag
echo \'</audio>\';
}
}
相关问答;A如果你在WordPress上。com,您可以使用[音频URL]快捷码。
如果你在WordPress上。org,您可以安装Jetpack插件来获取该短代码。该快捷码确定您的浏览器是支持flash还是html5,并选择合适的播放器。
有一个名为“Shortpack”的替代插件,如果您不想使用其他Jetpack功能,它只会为您提供Jetpack短代码。
您可以使用免费插件Audio Player 来自插件库。
我使用wp_editor() 在前端。默认情况下显示media\\u按钮if 访客已登录。无论用户是否登录,我都想显示这些媒体按钮。有没有办法做到这一点?