这里再贴一些代码,之前贴过在WordPress里放flash,视频,音乐的代码,详细可以看这“Wordpress插入音乐视频”。这次继续贴一些不错的。也方便自己以后使用。都是写php代码拉。呵呵~
1、1.插入Mp3音乐
在博客模板的function.php页面里增加如下代码
/**Mp3 player */ function mp3player($atts, $content=null){ extract(shortcode_atts(array("auto"=>'no',"loop"=>'no'),$atts)); return '<embed src="'.get_bloginfo(" template_url").'/player.swf?soundFile='.$content.'&bg=0xeeeeee&leftbg=0x357dce&lefticon=0xFFFFFF&rightbg=0xf06a51&rightbghover=0xaf2910&righticon=0xFFFFFF&righticonhover=0xffffff&text=0x666666&slider=0x666666&track=0xFFFFFF&border=0x666666&loader=0x9FFFB8&loop='.$loop.'&autostart='.$auto.'" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" width="290" height="30">'; } add_shortcode('mp3','mp3player');
调用方法:
[mp3]Yoururl.mp3[/mp3]默认关闭自动播放和循环 [mp3 auto="yes" loop="no"]Yoururl.mp3[/mp3]开启自动播放、关闭循环,其他自己组合就是Yes和No控制(无效果图,需要看的可以文章最下面的链接查看)2、下载文件添加图标同样是在function.php页面里增加:/** Download Image */ function jomor_download($atts, $content = null) { return '<a href="'.$content.'" target="_blank"><img src="http://jomor.org/download/download.gif" border="0" /></a>'; } add_shortcode("download", "jomor_download");调用方法:[download]Yoururl[/download](无效果图,需要看的可以文章最下面的链接查看)3、插入Google Adsense广告还是在function.php里面function adsense_shortcode( $atts ) { extract(shortcode_atts(array( 'format' => '1', ), $atts)); switch ($format) { case 1 : $ad = '<script type="text/javascript"><!-- google_ad_client = "pub-6928386133078955"; /* 234x60, created 16/09/08 */ google_ad_slot = "0834408702"; google_ad_width = 234; google_ad_height = 60; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>'; break; } return $ad; } add_shortcode('adsense', 'adsense_shortcode');调用方法:[adsense]4、插入相关文章还是老地方:function related_posts_shortcode( $atts ) { extract(shortcode_atts(array( 'limit' => '5', ), $atts)); global $wpdb, $post, $table_prefix; if ($post->ID) { $retval = '<ul>'; // Get tags $tags = wp_get_post_tags($post->ID); $tagsarray = array(); foreach ($tags as $tag) { $tagsarray[] = $tag->term_id; } $tagslist = implode(',', $tagsarray); // Do the query $q = "SELECT p.*, count(tr.object_id) as count FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < NOW() GROUP BY tr.object_id ORDER BY count DESC, p.post_date_gmt DESC LIMIT $limit;"; $related = $wpdb->get_results($q); if ( $related ) { foreach($related as $r) { $retval .= '<li><a title="'.wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li>'; } } else { $retval .= ' <li>No related posts found</li>'; } $retval .= '</ul>'; return $retval; } return; } add_shortcode('related_posts', 'related_posts_shortcode');调用方法:[related_posts limit="x"]
本文内容大部分引用:http://jomor.org/2010/02/02/wordpress-shortcodes 。非常感谢。
超越C++原创文章,转载请注明来源并保留原文链接
本文链接:http://www.beyondc.cn/wordpress-short-code-insert-music-advertising-downloads.html