Hello, thanks for your plugin.
I’m trying to display featured audio in a Block Request Loop or in category page but it doesn’t display the player.
Could you please help me with this ?
Thanks
Hi,
When I tried to use get_the_featured_audio(), I noticed that the album art is never shown. That’s because the variable $audio_attachment_id is never set in the function.
I fixed this, and also added the following features:
Can you include this extension in the next version of the plugin?
Here’s the updated code:
/**
* Get the featured audio, if it exists.
*
* @param $args array Display options.
* @param $args['id'] int Post id (optional). Defaults to current post id.
* @param $args['album_art'] boolean Whether to display the album art for the featured audio cycle. Default: false.
* @param $args['album_art_size'] string Size to use for the album art picture. Default: thumbnail.
* @param $args['title'] boolean Whether to display the title of the audio attachment. Default: false.
*
* @return string The featured audio markup.
*/
function get_the_featured_audio( $args = array() ) {
$args = wp_parse_args( $args, array(
'id' => null,
'title' => false,
'album_art' => false,
'album_art_size' => 'thumbnail'
) );
$audio_url = get_featured_audio_src( $args['id'] );
$audio_attachment_id = get_featured_audio_attachment_id( $args['id'] );
$output = '';
$outer_css_classes = '';
if ( $audio_url ) {
$thumb_id = '';
if ( $args['album_art'] ) {
$thumb_id = get_post_thumbnail_id( $audio_attachment_id );
$outer_css_classes .= ' has-album-art'
}
if ( $args['title'] ) {
$outer_css_classes .= ' has-title'
}
$output = '<div class="featured-audio' . $outer_css_classes . '">';
if ( ! empty( $thumb_id ) ) {
add_filter( 'wp_get_attachment_image_attributes', 'featured_audio_filter_album_art_image_attrs' );
$output .= wp_get_attachment_image( $thumb_id, $args['album_art_size'] );
remove_filter( 'wp_get_attachment_image_attributes', 'featured_audio_filter_album_art_image_attrs' );
}
$output .= '<div class="title-player-wrapper">';
if ( $args['title'] ) {
$output .= '<h3 class="featured-audio-title" style="clear: none;">' . get_the_title( $audio_attachment_id ) . '</h3>';
}
// Embedded audio player.
$output .= wp_audio_shortcode( array( 'src' => $audio_url ) );
$output .= '</div></div>';
}
return $output;
}
]]>
Just curious – Do I HAVE to host the audio file for this to work (I use Libsyn to host my podcast audio) or can I use a link to said audio for this plugin.
Love the work though thank you for making this.
]]>