该教程转自 扎尔克 ,因为我之前收藏的教程都失效了,所以我就转载下,不然回头又没了
短代码(shortcode)玩WordPress的人应该不陌生,有的时候为了视听效果,需要在文章中插入音乐,下面介绍个利用短代码在正文中加MP3的方法:
1、首先,在后台——外观——编辑——在右边模板中找到模版函数(functions.php),打开。
2、在模板函数functions.php结尾处插入以下代码:
<?php //mp3播放器短代码 function mp3player($atts, $content=null){ extract(shortcode_atts(array("auto"=>'0'),$atts)); return '<embed src="'.get_bloginfo("template_url").'/mp3player.swf?url='.$content.'&autoplay='.$auto.'" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" width="400" height="30">'; } add_shortcode('mp3','mp3player'); ?>
3、这里用到一个MP3player,把它下载下来,保存到当前使用的主题的wp-contentthemesxxxx(所用主题)文件夹下。
4、使用时,以[mp3 auto=”1″]歌曲链接[/mp3]形式插入,其中。auto=”1″可选,不填默认为auto=”0″,歌曲不自动播放。
此处贴上我加的个段代码的快捷插入函数
<?php
// add more buttons to the html editor
function appthemes_add_quicktags() {
?>
<script type=”text/javascript”>
QTags.addButton( ‘MP3’, ‘MP3’, ‘n[mp3 auto=”1″]歌曲链接[/mp3]’, ” );
</script>
<?php
}
add_action(‘admin_print_footer_scripts’, ‘appthemes_add_quicktags’ );
?>