我解开钩子wp_underscore_playlist_templates()
函数并创建我自己的版本prefix_wp_underscore_playlist_templates()
您应该首先返回或还原默认播放列表模板。(即钩回至wp_underscore_playlist_templates()
.)
添加然后将其添加到主题的主要功能中的某个位置。php文件:
add_action( \'wp_playlist_scripts\', function(){
?>
<script>
jQuery( function( $ ){
// Add the search box.
$( \'.wp-playlist\' ).prepend(
\'<p class="wp-playlist-custom-search alignright">\' +
\'<input class="search-playlist" placeholder="Search" />\' +
\'</p>\' +
\'<div style="clear: both;"></div>\'
);
// Performs the search.
$( \'.search-playlist\', \'.wp-playlist\' ).on( \'keyup\', function( e ){
var $playlist = $( this ).closest( \'.wp-playlist\' ),
query = this.value;
if ( ! query ) {
$( \'.wp-playlist-item\', $playlist ).show();
return;
} else if ( e.key.length > 1 ) {
return;
}
$( \'.wp-playlist-item-title\', $playlist ).each( function(){
var re = new RegExp( \'(\' + query + \')\', \'ig\' ),
title = $( this ).text();
if ( re.test( title ) ) {
$( this ).closest( \'.wp-playlist-item\' ).show();
} else {
$( this ).closest( \'.wp-playlist-item\' ).hide();
}
} );
} );
} );
</script>
<?php
} );
您将得到一个类似以下内容的搜索框:
在搜索时: