為了給我們的部落格文章內容豐富起來,有些時候我們需要給 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 的下載地址哈