為了給我們的博客文章內容豐富起來,有些時候我們需要給 WordPress 的文章內添加一些視頻、圖片和音樂,而今天介紹的 WordPress 教程是如何在 WordPress 通過短代碼實現漂亮的 mp3 音樂播放器功能!

首先介紹第一款播放器的實現方法是將下面代碼加入到 WordPress 主題文件的 function.php 內
- function doubanplayer($atts, $content=null){
- extract(shortcode_atts(array("auto"=>'0'),$atts));
- return '<embed src="'.get_bloginfo("template_url").'/shortcode/doubanplayer.swf?url='.$content.'&autoplay='.$auto.'" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" width="400" height="30">';
- }
- add_shortcode('music','doubanplayer');
使用方法是在文章編輯的時候:
- 通用音樂播放器
- 默認不自動播放:[music]http:
- 自動播放: [music auto=1]http:
第二款播放器的實現方法是將下面代碼加入到 WordPress 主題文件的 function.php 內
- function mp3link($atts, $content=null){
- extract(shortcode_atts(array("auto"=>'0',"replay"=>'0',),$atts));
- return '<embed src="'.get_bloginfo("template_url").'/shortcode/dewplayer.swf?mp3='.$content.'&autostart='.$auto.'&autoreplay='.$replay.'" wmode="transparent" height="20" width="240" type="application/x-shockwave-flash" />';
- }
- add_shortcode('mp3','mp3link');
使用方法是在文章編輯的時候:
- Mp3 專用播放器
- 默認不循環不自動播放:[mp3]http:
- 自動播放: [mp3 auto="1"]http:
- 循環播放: [mp3 replay="1"]http:
- 自動及循環播放:[mp3 auto="1" replay="1"]http:
最後將音樂播放器的 swf 文件上傳到 WordPress 主題文件夾的 shortcode 文件內,沒有的自建即可!詳情如下圖

最後小 2 提供兩個播放器 swf 的下載地址哈