Customize rtmedia gallery ( media-gallery-item.php ) with additional display like image, audio, video, etc. Are you having a problem adding custom information on the media gallery item? You don’t have to worry now, the codes below is the solution.
In my example, I want to add an audio player and the same time this is going to play when ajax is done updating the media list.
Put this in your functions.php
function rtmedia_audio_url() { global $rtmedia_backbone, $rtmedia_media; if( $rtmedia_backbone[ 'backbone' ] ){ echo '<%= audio_url %>'; }else{ return wp_get_attachment_url( $rtmedia_media->media_id ); } } add_filter( 'rtmedia_media_array_backbone', 'rtmedia_backbone_template_filter_custom', 10, 1 ); function rtmedia_backbone_template_filter_custom( $media_array ){ global $rtmedia_backbone, $rtmedia_media; $media_array->audio_url = wp_get_attachment_url( $media_array->media_id ); return $media_array; }
Inside of your media-gallery-item.php
<?php /** That's all, stop editing from here * */ global $rtmedia_backbone; $rtmedia_backbone = array( 'backbone' => false, 'is_album' => false, 'is_edit_allowed' => false ); if ( isset( $_POST[ 'backbone' ] ) ) { $rtmedia_backbone[ 'backbone' ] = $_POST[ 'backbone' ]; } if ( isset( $_POST[ 'is_album' ] ) ) { $rtmedia_backbone[ 'is_album' ] = $_POST[ 'is_album' ][ 0 ]; } if ( isset( $_POST[ 'is_edit_allowed' ] ) ) { $rtmedia_backbone[ 'is_edit_allowed' ] = $_POST[ 'is_edit_allowed' ][ 0 ]; } ?> <li class="rtmedia-list-item" id="<?php echo rtmedia_id(); ?>"> <?php do_action( 'rtmedia_before_item' ); ?> <a href ="<?php rtmedia_permalink(); ?>" title="<?php echo rtmedia_title(); ?>" class="<?php echo apply_filters( 'rtmedia_gallery_list_item_a_class', 'rtmedia-list-item-a' ); ?>"> <div class="rtmedia-item-thumbnail"> <?php echo rtmedia_duration(); ?> <img src="<?php rtmedia_image( "rt_media_thumbnail" ); ?>" alt="<?php rtmedia_image_alt(); ?>" > </div> <audio src="<?php echo rtmedia_audio_url(); ?>" width="20" height="20" type="audio/mp3" class="wp-audio-shortcode" id="bp_media_audio_<?php echo rtmedia_id(); ?>" controls="controls" preload="none"></audio> <?php if ( apply_filters( 'rtmedia_media_gallery_show_media_title', true ) ) { ?> <div class="rtmedia-item-title"> <h4 title="<?php echo rtmedia_title(); ?>"> <?php echo rtmedia_title(); ?> </h4> </div> <?php } ?> </a> <?php do_action( 'rtmedia_after_item' ); ?> </li>
See more details here Customize Media Gallery Template
Leave a Reply