, ,
Skip to content

WordPress widget 習作:FIFA CountDown

有點著涼,頭昏沉沉的,找些不用動腦的東西來練手指。將樂多熱血FIFA賽事倒數做成wordPress widgets12的版本,成果就像畫面右邊顯示的。

檔案放在: download fili_yam_fifa.txt
下載後放到plugins,改附檔名成.php,到管理介面啟動即可。mm…當然,還要到外觀裡的 Sidebar Widgets 設定顯示位置。

以下是實作的紀錄。

樂多熱血FIFA賽事倒數是flash做的,官方提供的建議HTML代碼是:(另有繁體中文版代碼3 )

<embed src="http://sports.yam.com/i/YamFifaEng.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="160" height="250"></embed>

某喵比較龜毛,作了一點點更改:4

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="160" height="250">
	<param name="movie" value="http://sports.yam.com/i/YamFifaEng.swf" />
	<param name="quality" value="high" />
	<embed src="http://sports.yam.com/i/YamFifaEng.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="160" height="250"></embed>
</object>

測試可動後,開始進行動工。

從wordpress widgets的說明檔中撿來基本的widget語法:

<?php
function widget_myuniquewidget($args) {
       extract($args);
?>
       <?php echo $before_widget; ?>
       <?php echo $before_title . 'My Unique Widget' . $after_title; ?>
               Hello, World!
       <?php echo $after_widget; ?>
<?php
}
register_sidebar_widget('My Unique Widget', 'widget_myuniquewidget');
?>

程式中用register_sidebar_widget登錄自己的函數後,在函數中印出widget標題’My Unique Widget’及內容’Hello, World!’。

將標題改成自己喜歡的,然後將之前的嵌入flash代碼取代原來的本文,就大功告成了。

從wordpress widgets的說明檔又撿來:

Don’t execute any code while the plugin is loaded. Use the plugins_loaded hook or you risk fatal errors due to undefined functions, or missing the boat completely because your plugin loaded before the one it depends on.

很好,add_action 的對象就是 ‘plugins_loaded’ 了。

以下就是完整的程式:

<?php
/*
Plugin Name: Fili Yam FIFA
Plugin URI: http://filitov.twcat.org/blog/?p=280
Description: An simple widget for <a href="http://blog.yam.com/fifa2006/archives/1646548.html">yam fifa 2006</a>
Version: 0.1
Author: Filitov Chang
Author URI: http://filitov.twcat.org/blog/
*/

function widget_fili_yam_fifa_widget_hook() {
	function widget_fili_yam_fifa($args) {
		extract($args);
	?>
		<?php echo $before_widget; ?>
			<?php echo $before_title . '2006 FIFA' . $after_title; ?>
			<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="160" height="250">
				<param name="movie" value="http://sports.yam.com/i/YamFifaEng.swf" />
				<param name="quality" value="high" />
				<embed src="http://sports.yam.com/i/YamFifaEng.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="160" height="250"></embed>
			</object>
		<?php echo $after_widget; ?>
	<?php
	}
	register_sidebar_widget('2006 FIFA', 'widget_fili_yam_fifa');
}

add_action('plugins_loaded', 'widget_fili_yam_fifa_widget_hook');

?>

寫這個東西大約花了五分鐘,寫部落格倒是用了15分鐘…XD….

  1. http://automattic.com/code/widgets/ []
  2. “Widgets” is just a silly buzzword we’ve chosen for this sidebar-chopping plug-in we have developed. They could have been called Gadgets or Gizmos or Wizbangs or Whatevers. []
  3. 奇怪的是:繁體中文版沒有倒數的部分… []
  4. 可參考Coolcode的這篇:网页内嵌多媒体内容的完美实现 []
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Taiwan License.

{ 1 } Trackback

  1. [...] 这个插件的制作基本参考了 喵爸爸的窩 的 WordPress widget 習作:FIFA CountDown。 [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *