我正在创建一个简单的音频WordPress主题,并在首页使用短代码[播放列表ID=“29,30,31,32,33,34]”呈现一个播放列表。如何仅列出标题(或艺术家)与输入中的文本匹配的歌曲?
经过几天的研究,我想出了这个方法wp_underscore_playlist_templates()
函数并创建我自己的版本prefix_wp_underscore_playlist_templates()
. 之后,我使用jQuery检查data.title
包含搜索字符串。这将仅正确列出与查询匹配的项目,但不会正确播放它们。如果搜索只过滤6个结果中的3个,并且您单击第3个过滤结果,它将播放原来位于第3个位置的歌曲。虽然不匹配wp-playlist-item
没有被添加到列表中,但不知何故它仍然存在于回放的内存中。我也是一名设计师,同时也是一名开发人员,所以请原谅我使用此解决方案的做法。
<script type="text/html" id="tmpl-wp-playlist-item">
<# if (data.title.toLowerCase().indexOf("SEARCH QUERY HERE") >= 0) { #>
<div class="wp-playlist-item">
<a class="wp-playlist-caption" href="{{ data.src }}" >
{{ data.index ? ( data.index + \'. \' ) : \'\' }}
<span class="wp-playlist-item-title">{{{ data.title }}}</span>
<# if ( data.artists && data.meta.artist ) { #>
<span class="wp-playlist-item-artist"> — {{ data.meta.artist }}</span>
<# } #>
</a>
<# if ( data.meta.length_formatted ) { #>
<div class="wp-playlist-item-length">{{ data.meta.length_formatted }}</div>
<# } #>
</div>
<# } #>
</script>